我使用FixtureAdapter在Ember Data 1.0 Canary上运行Ember 1.0。我的其中一条路线会在我第一次输入时正确加载模型,但随后的数据将为空。这是路线:
App.PlannerRoute = App.AuthenticatedRoute.extend({
model: function() {
var snapshotId,
scenarioController = this.controllerFor('scenario'),
snapshot = scenarioController.get('selectedSnapshot'),
scenario = scenarioController.get('content');
if ( !snapshot ) {
if ( !scenario )
this.transitionTo('scenarios');
else
this.transitionTo('scenario', scenario);
}
snapshotId = snapshot.get('id');
return Ember.Object.create({
regions: this.store.find('region', { snapshot: snapshotId }),
networks: this.store.find('networks', { snapshot: snapshotId }),
terminals: this.store.find('terminals', { snapshot: snapshotId })
});
}
});
如果我在上面的模型方法的return语句中设置了一个断点,我发现对this.store.find
的调用总是检索正确的数据。但是,数据仅在第一次转换到路径时填充到路径的controllers / views / templates / etc中。
对于追踪问题的任何帮助表示赞赏。我该如何解决这个问题?
答案 0 :(得分:0)
你有没有试过像:
...
snapshotId = snapshot.get('id');
var regions = this.store.find('region', { snapshot: snapshotId }),
networks = this.store.find('networks', { snapshot: snapshotId }),
terminals = this.store.find('terminals', { snapshot: snapshotId });
return Ember.RSVP.all([ regions, networks, terminals ]).then(function(results){
return Ember.Object.create({
regions: results[0],
networks: results[1],
terminals: results[2]
});
});