使用backbone的Model的集合的時候使用
self.fetch({
success : function(Collection,resp){
console.log(self.length) // 0
console.log(resp) //[{},{}] 有數(shù)據(jù)
}
});
無法把數(shù)據(jù)添加到集合中。
接口我使用的是nodejs的的接口get后數(shù)據(jù)是正常的
代碼我放到了git上,地址為:
后端:https://github.com/LuDongWei/demo/tree/master/node-address
前端:https://github.com/LuDongWei/demo/tree/master/backbone
在學習mvc的途中很糾結,希望幫助
閉關修行中......
In your source code https://github.com/LuDongWei/demo/blob/master/backbone/src/commentModel.js
, line 34, you override the parse method of Collection
and then return nothing, so nothing will be injected into Collection
. As follows:
parse : function(a,b){
// console.log(a)
// console.log(b)
}
Since nothing is implemented, delete the above parse
method and everything will be normal