Ember.js 将承诺结合在一起的正确方法
目前我正在做这件可怕的事:Ember.js 将承诺结合在一起的正确方法,ember.js,rsvp.js,Ember.js,Rsvp.js,目前我正在做这件可怕的事: //start the initial request request({ ... }).then(function(response1) { //Start a second request once the first has finished as it is dependent on the original request finishing
//start the initial request
request({
...
}).then(function(response1) {
//Start a second request once the first has finished as it is dependent on the original request finishing
request({
...
}).then(function(response2) {
...
}).catch(function(reason) {
...
});
}).catch(function(reason){
...
});
如何避免嵌入请求并将其包含在原始流中并避免嵌套?向then语句返回一个承诺,它将等待并在下一个链接
then
中使用该承诺
request({
...
}).then(function(response1) {
return request({
...
});
}).then(function(response2){
}).catch(function(reason){
...
});