I have an ember.js Object that overrides the create method so I can pass some json of unknown structure to the objects content variable.
//model
App.Order = Ember.Object.extend({
content: null,
create: function(data) {
this.set('content', data);
return this._super();
},
getView: function() {
var self = this;
return Ember.View.create({
templateName: 'order-dialogue',
classNames: ['card'],
content: self.get('content'),
name: 'house'
});
}
});
I have a function that generates a view for the object however I am unable to access the parent objects content. Everytime I try, self.get('content') returns null.
Quesion:
How can the view generated in the getView function access the parent objects content?
Actually your object is not overriding the create method. It is defining a create function on the instance. So with the code you posted,
To override the create method you need to
reopenClasslike this:With that in place:
Exactly the way you coded it. There is nothing wrong with the view, it actually is returning the parent object’s content. It’s just that the parent object’s content is not what you are expecting.
See this jsbin for a working example