我已經開始學習Backbone.js並試圖用Collections來編寫我的第一個應用程序。下面是代碼: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的第一個,下一個下劃線和骨幹。我一直得到「未定義不是函數」。請讓我知道如果我做錯了什麼。
謝謝!
你能找出哪一行產生錯誤嗎? – Floris 2013-04-05 11:15:10
'App.Models.Estimate = Backbone.Model.extend({});'等於'App.Models.Estimate = Backbone.Model;' – 2013-04-05 11:18:27
是的,我做到了。謝謝。 – abhididdigi 2013-04-05 17:58:09