0
exampleData = {
id: 1,
name: 'A',
house: {
address1: 'California'
address2: 'California'
}
}
House = Backbone.RelationalModel.extend({
urlRoot: function urlRoot() {
var personId = this.get('person').id; // this.get('person') is null
}
});
Person = Backbone.RelationalModel.extend({
relations: [
{ // Create a (recursive) one-to-one relationship
type: Backbone.HasOne,
key: 'house',
relatedModel: House,
reverseRelation: {
type: Backbone.HasOne,
key: 'person'
}
}
],
initialize: function() {
}
});
我需要人的模型數據在衆議院模型,骨幹關係一對一關係,如何得到父母的模型數據?
但this.get(「人」)返回null,即使我設置了reverseRelation。
我怎樣才能得到人的數據在家裏?
不應該你是在House模型中定義一個belongsTo關係? – Aukhan
houseModel.get(「person」) – Farside