backbone Collection fetch 返回的数据无法添加到集合


使用backbone的Model的集合的时候使用


 self.fetch({
        success : function(Collection,resp){
            console.log(self.length) // 0
            console.log(resp)  //[{},{}] 有数据
        }
    });

无法把数据添加到集合中。

clipboard.png

接口我使用的是nodejs的的接口get后数据是正常的

clipboard.png

代码我放到了git上,地址为:
后端: https://github.com/LuDongWei/demo/tree/master/node-address
前端: https://github.com/LuDongWei/demo/tree/master/backbone

在学习mvc的途中很纠结,希望帮助

backbone node.js

乱码字母人 11 years, 3 months ago

你的源码里 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)
}

既然什么都没实现,把上面这个 parse 方法删掉吧,一切就正常了

2235760 answered 11 years, 3 months ago

Your Answer