我已经开始学习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