[英]Ember: load models without waiting
是否可以在Ember中加載多個模型,而無需等待應許解決,而仍然使用afterModel掛鈎? 目前,我的代碼如下所示:
export default Ember.Route.extend({
model() {
return Ember.RSVP.hash({
imports: this.store.findAll('import', {
skip: 0,
limit: 5
}),
latestimport: this.store.find('import', 'latest')
});
},
afterModel(model) {
...some modifications here...
}
}
由於使用了Ember.RSVP,因此頁面加載會在呈現之前等待所有的Promise解析。 可以在加載模型之前使頁面呈現嗎? 然后,我仍然可以使用afterModel掛鈎嗎? 我的觀點是,正在加載的數據只是輔助信息。 因此,我不希望整個渲染過程都受阻。 盡管我覺得文檔根本不完整,但我在文檔中找不到任何信息。
請使用以下方法:
setupController(controller, model) {
this._super(controller, model);
Ember.RSVP.hash({
imports: this.store.findAll('import', {
skip: 0,
limit: 5
}),
latestimport: this.store.find('import', 'latest')
}).then(results => {
// ...some modifications here...
controller.set('model', results);
});
}
model.imports
, model.latestimport
。 而不是用Ember.RSVP.hash
包裝代碼,只需按Ember.RSVP.hash
傳遞哈希對象
model() {
return {
imports: this.store.findAll('import', {
skip: 0,
limit: 5
}),
latestimport: this.store.find('import', 'latest')
})
},
setupController(controller, model) {
this._super(controller, model);
// model.latestimport.then(...)
// model.imports.then(...)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.