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

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

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

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

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

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

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

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


你的源码里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方法删掉吧,一切就正常了

【热门文章】
【热门文章】