Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 具有2个承诺的余烬回报模型_Javascript_Ember.js - Fatal编程技术网

Javascript 具有2个承诺的余烬回报模型

Javascript 具有2个承诺的余烬回报模型,javascript,ember.js,Javascript,Ember.js,我有一个route类,在模板中,我使用一个自定义网格组件 {{my-grid params=this.gridParams elementId='myGrid'}} 现在,需要进行2个AJAX调用来填充网格 1. /getColumns (this column header data response is used to set some properties on my controller) 2. /getData (this body response is actually use

我有一个route类,在模板中,我使用一个自定义网格组件

{{my-grid params=this.gridParams elementId='myGrid'}}
现在,需要进行2个AJAX调用来填充网格

1. /getColumns (this column header data response is used to set some properties on my controller)
2. /getData (this body response is actually used to populate the grid with actual data and is actually computed to gridParams)
我在读“路由器暂停承诺”的指南

但是,这是针对单个promise/ajax调用的

我怎样才能使它在我的情况下工作

更新

我的普通单发请求

doPostReq: function(postData, requestUrl){
var promise = new Ember.RSVP.Promise(function(resolve, reject) {
    return $.ajax({            
    }).success(resolve).error(reject);
})

return promise;
},

如果你有两个或两个以上的承诺,并且想知道它们何时都解决了,或者

现在,在控制器中,您可以使用解析的承诺,如
model.columns
model.data

更新
如果您想要串行执行(一个接一个的承诺),那么您可以执行以下操作:

model() {
 let data;
 return this.getData().then(function(d){
   data = d;
   return this.getColumns();
 }).then(function(columns){
   return { columns, data };
 });
}

如果你有两个或两个以上的承诺,并且想知道它们何时都解决了,或者

现在,在控制器中,您可以使用解析的承诺,如
model.columns
model.data

更新
如果您想要串行执行(一个接一个的承诺),那么您可以执行以下操作:

model() {
 let data;
 return this.getData().then(function(d){
   data = d;
   return this.getColumns();
 }).then(function(columns){
   return { columns, data };
 });
}

酷..谢谢..再问两个问题;1.我希望在列之后调用数据。那我怎么处理呢?二,。我可以将这个散列解决方案转换成某种形式的公共代码,就像我目前对单个请求所做的那样;doPostReq(请看我的更新)如果你想要一个接一个的串行执行,那么你不需要任何来自RSVP的帮助函数,实际上我的意思是这是一个针对两个请求的AJAX服务器调用…这就是我想在它里面使用Ember.RSVP.Promise和使用$.AJAX()的原因冷却..谢谢..还有两个问题;1.我希望在列之后调用数据。那我怎么处理呢?二,。我可以将这个散列解决方案转换成某种形式的公共代码,就像我目前对单个请求所做的那样;doPostReq(请参阅我的更新)如果你想一个接一个地执行序列,那么你不需要RSVP的任何帮助函数,实际上我的意思是这是对这两个请求的AJAX服务器调用…这就是我想在其中使用Ember.RSVP.Promise和使用$.AJAX()的原因可能重复的