backbone.js - 未定义不是函数

时间:2013-04-05 11:13:40

标签: backbone.js

我已经开始学习Backbone.js并试图用Collections编写我的第一个应用程序。这是代码:

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,下一个是Underscore和Backbone。我一直得到“未定义不是一个功能”。如果我做错了,请告诉我。

谢谢!

1 个答案:

答案 0 :(得分:2)

您确定要将集合App.Collections.Estimate作为模型分配给它吗?

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