Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4838

Router - setting a property from within the model hook

$
0
0

@therealbenhogan wrote:

Hi,

I have a router (eg products) where I want to determine dynamically, based on the response of the json api, whether to display a listing of categories or items.

In my router I have a property

isCategories:false

and in the model hook something like this, where I want to be able to change the isCategories property depending on the value returned from the api call - true/false

model() {
   Ember.$.post('/api/products/showCategoriesOrItems').then(function(answer) {
        // I can't use this.set('isCategories',true) for example
   });
}

What I then want to do is return the model depending upon the revised value of isCategories so something like

if (this,get('isCategories')) {
     return this.store.findAll('product-category');
}
else {
     return this.store.findAll('product')
}

Any help much appreciated!

Posts: 6

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4838

Trending Articles