$.when() 传入数组

542 阅读1分钟
txidArr是所有要调接口的参数数组;代码如下:
let dtdArr = [];
$.each(txidArr, (index, txid) => {
	function getDef() {
		let dtd = $.Deferred();
		$.ajax({
			type: 'GET',
			url: `${baseUrl}/transactions/${txid}`
		}).done((txRes) => {
			dtd.resolve(txRes);
		})
		return dtd;
	}
	dtdArr.push(getDef())
});

$.when.apply(this, dtdArr).then(function(...args) {
      console.log(args);
})