官方documentation for DS.Model描述:DS.Model`relationships`屬性在記錄的`init`中不可用?
當我這樣做:
App.Parent = DS.Model.extend({
children: DS.hasMany('child'),
init: function() {
this._super();
this.eachRelationship(function(foo, bar, baz) {
console.log('each relationship', foo, bar, baz);
});
}
});
...它打印出的children
關係。
然而,當我這樣做:
App.Parent = DS.Model.extend({
children: DS.hasMany('child'),
init: function() {
this._super();
console.log('realtionships', this.get('relationships'));
}
});
...它打印undefined
!
爲什麼?我如何在記錄初始化期間訪問relationships
屬性,而不回覆到eachRelationship
方法?
演示:http://emberjs.jsbin.com/vapama/9/edit?js,output
真棒,這正是我想要的。謝謝。 – 2015-01-04 17:58:02