mercredi 2 novembre 2016

How to access the parent controller from the child routes in Ember JS?

I have a main route named list.

//items/list/route.js
setupController(controller, items) { 
    let vegItems = Ember.A([]);
    let nonVegItems = Ember.A([]);
    items.forEach((item) => {
        if (item.get('category') === "veg") {
            vegItems.pushObject(item);
        }

        if (item.get('category') === "non_veg") {
            nonVegItems.pushObject(item);
        }
    })

    controller.set('vegItems', vegItems)
    controller.set('nonVegItems', nonVegItems);
}

Now inside the list route, I have the routes named veg and non-veg. i.e list/veg and list/non-veg. How can I access the controller variables of parent route, i.e vegItems and nonVegItems from list/route.js to the child route to load the data in list/veg/template.hbs and list/non-veg/template.hbs?




Aucun commentaire:

Enregistrer un commentaire