0

我有我的看法:

var TryView = Backbone.View.extend({

initialize: function(){
    this.render();
},

render: function(){

    var test = this.collection.get(0);
    this.collection.each(function(model){
    document.write(model.id+"<br>");
    });
}

});

以及使用一些现有(工作)集合创建它的顺序。

var testView = new TryView({collection: test.TestCollection});

但我得到了错误:

对象函数 (){ parent.apply(this, arguments); 没有方法'get'

和 fetch 一样

4

2 回答 2

3

您正在尝试调用 get on the 'class' test.TestCollection。当你这样做时

var testView = new TryView({collection: test.TestCollection});

您将 TestCollection 'class' (js 中实际上没有类,只有函数)作为collectionView 的 -attribute。您必须提供 TestCollection 的实例

var testCollection = new test.TestCollection();
var testView = new TryView({collection: testCollection});

希望这可以帮助!

于 2013-01-22T16:00:43.477 回答
0

传递集合实例

new TryView({collection: new test.TestCollection});

于 2013-01-22T15:59:49.003 回答