集合没有被填充 - backbone.js

时间:2013-01-17 19:00:37

标签: javascript backbone.js

我的集合类中有一个fetch方法,可以从我指定的url中正确记录控制台中的响应。来自网址的响应在控制台中显示如下,

[
Object
Desc: "Desc of Qn0"
Qno: 0
__proto__: Object
, 
Object
Desc: "Desc of Qn1"
Qno: 1
__proto__: Object
, 
Object
Desc: "Desc of Qn2"
Qno: 2
__proto__: Object
, 
Object
Desc: "Desc of Qn3"
Qno: 3
__proto__: Object
, 
Object
Desc: "Desc of Qn4"
Qno: 4
__proto__: Object
] 

获取方法如下,

app.collections.CollectionItems.fetch({

                success: function (collection,response) {
                    console.log(response);
                    //console.log(response[0].Desc);
                    //app.collections.CollectionItems.add(response);
                    console.log(app.collections.CollectionItems.length);
                    app.views.app = new app.views.masterView({collection: app.collections.CollectionItems});
                }
            });

现在,当我尝试记录集合的长度时,它表示为零。为了证实我的疑问,我试图遍历集合中的模型(在视图的渲染方法内),这表明集合没有模型。我应该用fetch()来填充集合吗?

0 个答案:

没有答案