[英]Looping through an Ember JS RSVP hash?
代碼講一千個字; 有什么辦法可以做我在這里嘗試的事情嗎?
用戶“根”路由
在頂層加載常用的可選選項,以在子路由中使用,例如index
, show
, edit
, create
等等。
-- /pods/users/route.js
model() {
return RSVP.hash({
userCategories: this.store.findAll('user-category'),
userSources: this.store.findAll('user-source'),
userGroups: this.store.findAll('user-group'),
});
},
用戶“創建”路線
通過/create
的子路由,我想遍歷上面已經加載的選項,並將它們作為命名變量加載到模板中:
-- /pods/users/create/route.js
setupController(controller, model) {
let rootModel = this.modelFor('users');
rootModel.forEach(function (model, name) {
set(controller, name, model);
}); <-- THIS IS THE BROKEN PART...
...
}
問題
在.forEach
循環上,我Error while processing route: rootModel.forEach is not a function TypeError: rootModel.forEach is not a function
時遇到Error while processing route: rootModel.forEach is not a function TypeError: rootModel.forEach is not a function
是否存在遍歷該根模型的“ Ember Way”,或者我會被困在將其加載到頂級變量中的問題,即;
-- /pods/users/create/route.js
setupController(controller, model) {
let rootModel = this.modelFor('users');
set(controller, 'rootModel', rootModel);
...
}
Object.keys(rootModel).forEach(function(name) {
var model = rootModel[keyName];
set(controller, name, model);
// ...
});
或者可能你只是不需要RSVP.hash
但RSVP.all
其返回與數組包含解析值解決了一個承諾?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.