2013-04-05 3 views
1

Backbone.js를 배우기 시작했으며 컬렉션으로 첫 번째 앱을 작성하려고했습니다.backbone.js - 정의되지 않은 함수가 아닙니다.

console.clear(); 
(function($){ 

    window.App = { 

     Models : {}, 
     Collections : {}, 
     Views : {} 

    }; 



    //a single estimate 
    App.Models.Estimate = Backbone.Model.extend({}); 

    // multiple esitmates 
    App.Collections.Estimates = Backbone.Collection.extend({ 


     model : App.Collections.Estimate 


    }); 


    App.Views.Estimates = Backbone.View.extend({ 
     tagName: 'ul', 


     render : function(){ 

     this.collection.each(this.addTo,this); 

    }, 
     addTo:function(estimate){ 

     var dir = App.Views.Estimate({model:estimate}).render(); 
     this.$el.append(dir.el); 

     } 





    }); 


    App.Views.Estimate = Backbone.View.extend({ 
     tagName: 'li', 


     render :function(){ 

     this.$el.html(this.model.get('title')); 
     return this; 
     } 


    }); 



    var jSon = [{title:'Abhiram', estimate:8}]; 
    var estimates = new App.Collections.Estimates(jSon); 
    console.log(estimates); 

    var tasksView = new App.Views.Estimates({collection:estimates}); 
    // var a = tasksView.render().el; 
    //console.log(a); 

})($j||jQuery); 

나는 모든 세 가지가 포함 시켰습니다 :

jQuery를 먼저 밑줄 다음과 백본 여기에 코드입니다. 나는 계속 "Undefined is not function"을 얻고 있습니다. 내가 잘못하고 있다면 알려주십시오.

감사합니다.

+0

오류를 생성하는 행을 찾을 수 있습니까? – Floris

+0

'App.Models.Estimate = Backbone.Model.extend ({});는'App.Models.Estimate = Backbone.Model; '과 같습니다. –

+0

예, 그랬습니다. 고맙습니다. – abhididdigi

답변

2

컬렉션 App.Collections.Estimate을 모델로 할당 하시겠습니까?

// multiple esitmates 
App.Collections.Estimates = Backbone.Collection.extend({ 
    model : App.Collections.Estimate 
}); 
+0

도와 주셔서 감사합니다. 그것은 그것을 고쳤다. – abhididdigi

+0

무엇을 변경 했습니까? – Aspen

관련 문제