簡體   English   中英

遍歷Ember JS RSVP哈希?

[英]Looping through an Ember JS RSVP hash?

代碼講一千個字; 有什么辦法可以做我在這里嘗試的事情嗎?

用戶“根”路由

在頂層加載常用的可選選項,以在子路由中使用,例如indexshoweditcreate等等。

-- /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.hashRSVP.all其返回與數組包含解析值解決了一個承諾?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM