使用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
在學(xué)習(xí)mvc的途中很糾結(jié),希望幫助
閉關(guān)修行中......
你的源碼里https://github.com/LuDongWei/demo/blob/master/backbone/src/commentModel.js
,第34行,你override了Collection
的parse方法,然后還什么都沒返回,那必然沒有東西會被注入到Collection
里去了。如下:
parse : function(a,b){
// console.log(a)
// console.log(b)
}
既然什么都沒實(shí)現(xiàn),把上面這個parse
方法刪掉吧,一切就正常了