0
後,我有一個嵌入式收集骨幹模型,我使用「解析」功能:骨幹集合了空模型獲取
var OrderModel = Backbone.Model.extend({
urlRoot:'/handlers/order',
defaults:{
'id':'',
'name': '',
'history': new HistoryCollection()
},
parse: function(response){
this.set({'id': response.id});
this.set({'name': response.name});
var historyList = new HistoryCollection();
historyList.add(response.history);
this.set({history: historyList});
}
})
收集
從視圖var OrderCollection = Backbone.Collection.extend({
url: '/handlers/orders/',
model: OrderModel,
parse:function(response){
return response;
}
});
代碼:
var c = new OrderCollection();
this.collection.fetch().complete(function(){
console.log(c);
});
我的服務器返回JSON,未按照模型填充。 但如果我從OrderModel刪除「解析」功能的所有作品
謝謝,安德魯!有用! – Linkorn