1

尝试编写集合视图时,我得到这个未捕获的对象类型错误不是函数。我在做应用程序时使用了相同的代码,但是当我用 require.js 做应用程序时,我收到了这个错误。请帮我。这是代码:

define([
  'underscore',
  'backbone',
  // Sub Views
  'view/todo_view'
],function(
  _,
  Backbone,
  // Sub Views
  TodoView
){
    return Backbone.View.extend({
      el:$('#todos'),

      render: function(){
        this.collection.forEach(this.addOne,this);
        return this;
      },

      addOne: function(todoIt1){            
        var todoView = new TodoView({
          model: todoIt1
        });
        this.$el.append(todoView.render().el);
      }

    });

  });
4

1 回答 1

2

This kind of error happens when using the operator new with an object, and not a function. You should check if TodoView really is a function, and not an instance of TodoView. If that's the case, make sure you didn't misplace a new operator in your TodoView file.

于 2013-06-19T14:49:45.693 回答