My model includes a field with an array of objects structured like this:
App.Post = DS.Model.extend({
...
codes: attr(),
...
});
and the 'Codes' object looks like this:
codes: [
{
code: stuff,
comment: stuff_1,
other_things: other_stuff
},
{
...
},
{
...
}
...
]
I have an add/remove button with actions attached. The functions associated with them are as follows:
add_code_input: function() {
var codes = this.get('model.codes');
var self = this;
var last_code = codes[codes.length-1];
// Unable to edit due to ember.set error
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);
}
The remove operation works fine, but adding new items does not.
When attempting to update last_code
, I receive the following error message:
Uncaught Error: Assertion Failed: You must use Ember.set() to access this property (of [object Object])
I am trying to insert a dummy object that users can modify.
The first issue is correctly inserting dummy objects into the array, and the second is updating the template when the model changes.