2013-01-22 4 views
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}); 

하지만 난 오류 얻을 : 가져

Object function(){ parent.apply(this, arguments); } has no method 'get'

과와 같은

+0

어디에서 test.TestCollection을 할당합니까? TestCollection은 Backbone 컬렉션 대신 함수입니다. –

답변

3

'클래스'test.TestCollection. 이

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

을 수행 할 때 당신은을 TestCollection '클래스'를 제공보기에 collection -attribute로 (JS에는 클래스, 단지 기능이 정말 없다). TestCollection의 인스턴스를 제공해야합니다.

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

희망이 있습니다.

0

패스 수집 인스턴스

new TryView({collection: new test.TestCollection}); 당신은 타고 전화를 위해 노력하고