【问题标题】:backbone.js - Undefined is not a function主干.js - 未定义不是一个函数
【发布时间】:2013-04-05 19:17:50
【问题描述】:

我已经开始学习 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,其次是下划线,然后是 Backbone。我不断收到“未定义不是函数”。如果我做错了什么,请告诉我。

谢谢!

【问题讨论】:

  • 你能找出是哪一行产生了错误吗?
  • App.Models.Estimate = Backbone.Model.extend({}); 等于 App.Models.Estimate = Backbone.Model;
  • 是的,我做到了。谢谢。

标签: backbone.js


【解决方案1】:

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

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

【讨论】:

  • 感谢您帮助我。这解决了它。
  • 你改成什么了?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-03-16
  • 2015-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-07
  • 1970-01-01
相关资源
最近更新 更多