Reputation: 71
I'm trying to get to my models data from a view didInsertElement hook, because I need to trigger some actions on the DOM when the template rendering is completed.
with models like:
App.MyParent = DS.Model.extend({
title: DS.attr('string'),
childs: DS.hasMany('App.MyChild')
});
App.MyChild = DS.Model.extend({
name: DS.attr('string'),
parent: DS.belongsTo('App.MyParent')
});
and objects like:
App.MyParent.FIXTURES = [
{ id: 0, title: "some title", childs: [0,2,3] }
]
App.MyChild.FIXTURES = [
{ id: 0, name: "some name", parent: 0 },
{ id: 2, name: "other name", parent: 0 },
{ id: 3, name: "diff name", parent: 0 }
]
Inside the hook function I am getting to the childs property like this:
var childs = this.get("context.content.childs");
then I get an enumerable with the right number of childs, but the child all have undefined properties.
update Seems like the only place where I can get to a child with App.MyChild.find(someId) is in the browser console, in my app code I only get objects with undefined properties.
I'm puzzled!
Upvotes: 0
Views: 174
Reputation: 19050
To access the childs property, try something like this:
var childs = this.get("context.content.childs");
Also, the fixture data for associations should not use _id or _ids. So use childs
and parent
instead:
App.MyParent.FIXTURES = [
{ id: 0, title: "some title", childs: [0,2,3] },
];
App.MyChild.FIXTURES = [
{ id: 0, name: "some name", parent: 0 },
{ id: 2, name: "other name", parent: 0 },
{ id: 3, name: "diff name", parent: 0 },
];
Upvotes: 1