javascript - Ember.js: let component observe value changes of store items -
i starting use ember , came across following problem. want observe whether or not there has been change of value of item within store. far understand, @each directive for. unfortunately, not trigger respective method in component.
my code structured follows. current route returns subset of store , has action changes 1 of items.
export default ember.route.extend({ model: function() { this.store.push('node', {id: 1, x: 40, y:40}); this.store.push('node', {id: 3, x: 50, y:50}); return this.store.findall("node"); }, actions: { move: function(x, y) { this.store.findrecord('node', 1).then( function(v) { v.set("x", x); v.set("y", y); }); } } });
i pass model via template directive component.
{{node-comp data=model}}
now, want notification within component, when value in model changes (i.e. in example action 'move' called). current approach looks following:
export default ember.component.extend({ rerender: function() { console.log("rerender called"); }.observes("data.@each") };
i tried 'data.[]' directive , 'data.@each.x' directive well. nothing led desired behaviour. notice template of component notified, i.e., list of items of model gets updates after 'move' call.
my 'ember -v' output
future versions of ember cli not support v4.2.0. please update node 0.12 or io.js. version: 1.13.8 not find watchman, falling nodewatcher file system events. visit http://www.ember-cli.com/user-guide/#watchman more info. node: 4.2.0 npm: 2.13.4 os: linux x64
you try using "hasdirtyattributes" property. i'm not sure if applies when pushing {x: 1} objects. why not use store.createrecord('node', {x: 1}) etc.
http://emberjs.com/api/data/classes/ds.model.html#property_hasdirtyattributes
rerender: function() { console.log("rerender called"); }.observes("data.@each.hasdirtyattributes")
nb! not work async relations
btw rerendering looks weird.
what component contains of ? looks odd rendering after model change, can have direct bindings of model values in component. component/file.js
{{#each data |node|}} {{node.x}} < changes when node changes {{/each}}
Comments
Post a Comment