当我做这样的事情时:
Ember.$.getJSON(url)
.then(function(response){
return Ember.RSVP.all(response.map(Ember.$.getJSON))
})
.then(function(response){
// this is where the oddity begins
console.log(response)
})在本地环境(Ember1.13.5)上的应用程序路由器的model钩子中,我在第二个then()的响应中得到了一个奇怪的响应,比如:
Promise: {
_id: 48
_label: undefined
_result: Array[1]
_state: 1
_subscribers: Array[0]
__proto__: Promise
}我可以在第二个then中做一个then来获得我正在寻找的响应,但这并不理想,因为我想要连锁承诺。
我尝试在JSBin上设置相同的示例,使用Ember.run.later作为承诺:JSBin实例。这种方法在这里似乎运作得很好。
我是不是遗漏了什么?
发布于 2015-07-25 01:57:59
事实证明,Ember.$.ajax()和Ember.$.getJSON()是罪魁祸首。他们正在使诺言链失效。将getJSON替换为:
new Ember.RSVP.Promise(function(resolve, reject){
Ember.run.later(function(){
console.log('resolving first fake promise');
var response = [{id: 1, pool: 1, collection: 1}, {id: 2, pool: 2, collection: 1}];
resolve(response)
},1000)
})它起作用了。因此,我转向成员-cli-ic-ajax,并使用它来处理getJSON部分,它工作得很好。
干杯,jQuery。干杯。
https://stackoverflow.com/questions/31621893
复制相似问题