kyrre
kyrre

Reputation: 646

Ember-Data parent template not updating when model is changed

I am using EAK with a simple nested routing structure, but changing the parent model in the child controller does not change the top-level view. For example if I have the following router.js file:

this.resource('similar', function() {
    this.resource('list', { path: '/list/:phone_id' });
    this.resource('upload');
    this.resource('new');
});

For the 'similar' route model I am using ember-data together with the RESTAdapter which is backed Flask.

export default Ember.Route.extend({
    model: function() {
        return this.store.find('phone');
    }
});

If I manipulate the model inside the 'upload' controller then the changes are not reflected in the template, e.g.

var record = this.store.createRecord('phone', {
    numbers: [1,2,3,4]
});

record.save();

will not change "{{#each list in model}} {{list.numbers}} {{/each}}". If I reload the page it works fine. What am I doing wrong?

Upvotes: 0

Views: 630

Answers (2)

kyrre
kyrre

Reputation: 646

The problem here was that the REST endpoint did not return the new record (with the id attribute set).

Upvotes: 0

raycohen
raycohen

Reputation: 740

Instead of store.find which hits the server and stores that exact list, try using store.filter. store.filter "remains up to date as new records are loaded into the store or created locally"

http://emberjs.com/api/data/classes/DS.Store.html#method_filter

Upvotes: 0

Related Questions