javascript - Ember not updating template when I add or remove an object from an array field in the model -
so i've got model has field of array objects looks
app.post = ds.model.extend({ ... codes: attr(), ... }); , codes looks codes: [ { code: stuff comment: stuff_1 other_things: other_stuff }, { ... }, { ... } ... ]
so have add together / remove button has actions attached them ,
add_code_input: function() { var codes = this.get('model.codes'); var self = this; var last_code = codes[codes.length-1]; // cannot edit ember.set error occurring last_code.code = 'add new (please change)'; last_code.code_type = ""; last_code.comment = ""; console.log(last_code); codes.push(last_code); this.set('model.codes', codes); console.log(codes); }, remove_code_input: function() { var codes = this.get('model.codes'); codes.pop(); console.log(codes); this.set('model.codes', codes); }
so remove works fine add together doesn't work.
it gives me error when seek update last_code
: uncaught error: assertion failed: must utilize ember.set() access property (of [object object])
i want add together dummy object user can change.
so first issue figuring out how add together dummy objects array , secondly how update template model changes.
you should using arr.pushobject(obj)
, arr.popobject()
manipulating array in ember (think of setter/getter of arrays).
is codes attr()
because appears behaving ds record.
if record, utilize record.set('foo', 'bar')
if it's pojo can utilize ember.set(obj, 'foo', 'bar')
.
it should easy (i'm assuming you're using , in objectcontroller here)
var newcode = { code:'foo' }; this.get('codes').pushobject(newcode);
javascript arrays ember.js
No comments:
Post a Comment