有没有办法访问嵌入模型对象的父对象?例如:
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')
});
最佳答案
为什么不简单地设置一个 belongsTo
关系?
App.Email = DS.Model.extend({
person: DS.belongsTo('App.Person')
//...
});
然后您将能够使用电子邮件的 person
属性。
关于ember.js - 从嵌入对象访问父记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12911419/