在我的路由模型中,我需要发送两个请求(以前的和最新的),并在响应中获取他们的 ID 以发送另外两个请求(baslineCpature 和 currentcapture)。当我得到两个请求的响应时,我需要发送另外两个请求(fiberHealthData、wavelengthsPerSectionData)。ember 模型应该返回(baslineCpature、currentcapture、fiberHealthData、wavelengthsPerSectionData)。我在这里遇到的一个问题是,我想在收到 baslineCpature 和 currentcapture 的响应后立即更新我的模板。
这是我的代码。如果有人能告诉我我做错了什么,我将不胜感激。
model: function (params,transition) {
var promiseA=null;
var promiseB=null;
var promiseA1=null;
var promiseB1=null;
promiseA1 = Ember.RSVP.hash({
latest:this.store.findAll('latest'),
previous: this.store.findAll('previous'),
});
promiseA= promiseA1.then((promiseAResolved) => {
return Ember.RSVP.hash({
baselineCapture:self.store.find('capture', promiseAResolved.previous.get('firstObject.id')),
currentCapture: self.store.find('capture', promiseAResolved.latest.get('firstObject.id')),
});
});
promiseB= promiseA.then((promiseAResolved) => {
baselineId = promiseAResolved.baselineCapture.id;
currentId = promiseAResolved.currentCapture.id;
return Ember.RSVP.hash({
fiberHealthData:self.store.findAll('fiber-health',{ adapterOptions: {current: currentId, baseline: baselineId}}),
wavelengthsPerSectionData:self.store.findAll('wavelengths-per-section',{ adapterOptions: {current: currentId, baseline: baselineId}} )
});
});
//this should be retun of my model
return Ember.RSVP.hash({
baselineCapture:promiseA.baselineCapture,
currentCapture:promiseA.currentCapture,
fiberHealthData:promiseB.fiberHealthData,
wavelengthsPerSectionData:promiseB.wavelengthsPerSectionData,
});
}