Ember Model get is not a function

时间:2015-07-28 16:22:16

标签: ember.js

Why sometimes in setup controller on my product route, model.get('property') works and other times I have to retrieve properties with model.property

It throws an error

model.get( is not a function...

Why is this happening, clues?

Details :

Product Route -

model: function(params) {
    return this.store.find('product', params.product_id);
},

setupController: function(controller, model){
    this._super(controller, model);

    var type = model.get('publisher').get('entity_type');
}

Index Route -

model: function(params){
    return Ember.RSVP.Promise.all([
        this.store.find('groupedItem', { group_code: 'HOME', position : 1 }),
        this.store.find('groupedItem', { group_code: 'HOME', position : 2 }),

    ])
}

1 个答案:

答案 0 :(得分:1)

你在setupController钩子中调用了一个异步方法,这是Ember没想到的。您可能在将模型实际放置在控制器上之前尝试调用model.get()。这种异步操作应该在model()钩子中进行,而不是在setupController()钩子中。

model: function() {
    return Ember.RSVP.Promise.all([
        this.store.find('groupedItem', { group_code: 'HOME', position : 1 }),
        this.store.find('groupedItem', { group_code: 'HOME', position : 2 })
    ]);
},

// This is actually the default behavior of this method
// So you don't have to override it if you don't want to
setupController: function(controller, model) {
    // The `model` is your `values`
    controller.set('model', model);
}