I have an array which is deep into an Ember-data model(the votes inside the pics inside the imagepost):
App.Imagepost = DS.Model.extend({
title: DS.attr( 'string' ),
pics: DS.attr(), // array of objects
});
App.Imagepost.FIXTURES = [
{
id: 1,
title: 'First day of school outfit',
pics: [
{
url: 'https://example.com/wow.jpg',
votes: [1, 22, 55] // List of voters' ids
},
{
url: 'https://example.com/funny.jpg',
votes: [7] // List of voters' ids
}
]
}
]
Now I want to remove a vote from it but without using x.set(); the change is not reflected into the template nor into Ember-data
This is my code(ImageController):
var ob = this.get('model').objectAt(0).get('pics').objectAt(0);
console.log(ob);
votes_array.splice(user_id_index, 1);
ob.set('votes', votes_array);
console.log(ob);
Gives the following error: (on the ob.set line)
Uncaught TypeError: undefined is not a function
So if I try it like this:
var ob = this.get('model').objectAt(0).get('pics').objectAt(0);
console.log(ob);
ob.votes = [];
console.log(ob);
I get this error:
Uncaught Error: Assertion Failed: You must use Ember.set() to access this property (of [object Object])
If I could change this weird and long line:
this.get('model').objectAt(0).get('pics').objectAt(0);
Into something like:
this.get('model[0].pics[0]'));
Maybe it could work since i could do the same thing with a set instead of a get but this method doesnt work(how can i access an array? my controller is ArrayController but with this.get() i can't really access my model)
But for now I just can't figure it out, I just want to make votes: [1, 22, 55] into [22, 55] from the controller and that the change will be reflected in the template & Ember-data.
By the way if I change the array in a compnent it doesn't reflect the changes either.
Also something weird this line gives me undefined although the title is set:
this.store.find('imagepost', 1).get('title')