有没有办法访问嵌入式模型对象的父对象?例如:
App.Person = DS.Model.extend({
name : DS.attr('string'),
emails : DS.hasMany('App.Email', { embedded: true })
});
App.Email = DS.Model.extend({
label : DS.attr('string'),
email : DS.attr('string'),
setParentUpdated: function() {
if(this.get('isDirty') == true)
// this.get('parent').get('stateManager').goToState('updated');
// I would like to do something like this.get('parent')
// to access 'App.Person' instance object
}.observes('isDirty')
});
答案 0 :(得分:5)
为什么不简单地设置belongsTo
关系?
App.Email = DS.Model.extend({
person: DS.belongsTo('App.Person')
//...
});
然后您就可以使用电子邮件的person
属性。