samedi 28 mai 2016

Looping through an Ember JS RSVP hash?

Code speaks a thousand words; is there a way to do what I'm attempting here?

Users "Root" Route

Loading common selectable options at the top level for use within sub-routes such as index, show, edit, create, etc...

-- /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'),
    });
},

Users "Create" Route

With the sub-route of /create I want to loop through the already-loaded options above and load them into the template as named variables:

-- /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...

    ...

}

The Problem

On the .forEach loop I am getting Error while processing route: rootModel.forEach is not a function TypeError: rootModel.forEach is not a function

Is there an "Ember Way" of looping through that root model, or will I be stuck with loading it in within a top level variable, ie;

-- /pods/users/create/route.js

setupController(controller, model) {

    let rootModel = this.modelFor('users');

    set(controller, 'rootModel', rootModel);

    ...

}




Aucun commentaire:

Enregistrer un commentaire