【问题标题】:Getting all resolved data inside $.when在 $.when 中获取所有已解析的数据
【发布时间】:2017-02-06 13:41:22
【问题描述】:

我正在检查如何在 $.when(null, promArr) 中获取所有已解析的数据

然后我得到了最后一个解析的数据。但我需要得到所有已解决的东西。

var  _promArr = [],_prom = ''; 
        _.each(uniqueAccountList, function(obj,idx){
            _prom = getAccountDetails(obj.acctId);  
            _promArr.push(_prom); 
        });
        $.when.apply(null, _promArr).then(function(){ 

           ***I need all data passed inside resolve  here***

        }).always(function () {
            console.log('all joint promises resolved always');
        });
function getAccountDetails(accid){

  // perform ajaxcall and resolve or reject the promise

  var _def = $.Deferred();

  if (successs)
     _def.resolve({accid:accid,status:1})
  else if (fail.reason == 'Not found')  
     _def.resolve({accid:accid,status:0})
  else
     _def.reject();

  return _def
}

【问题讨论】:

    标签: jquery jquery-deferred resolve


    【解决方案1】:

    然后我们可以使用 arguments

    来获取里面的所有解析数据
    $.when.apply(null, _promArr).then(function(){ 
    
           ***I need all data passed inside resolve  here***
    var resolvedData = JSON.parse(JSON.stringify(arguments));
    
    
        }).always(function () {
            console.log('all joint promises resolved always');
        });
    

    【讨论】:

      猜你喜欢
      • 2021-10-04
      • 2015-02-10
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多