【发布时间】:2013-05-31 06:47:23
【问题描述】:
使用 Backbone 0.9.2 我试图取消绑定视图中的某些元素,但出现以下错误
未捕获的类型错误:无法调用未定义的方法 'unbind'
console.log('+++ Kill: ', this);
this.model.unbind( 'change', this.render, this ); // Unbind reference to the model
this.options.parent.unbind( 'close:all', this.close, this ); // Unbind reference to the parent view
delete this.$el; // Delete the jQuery wrapped object variable
delete this.el; // Delete the variable reference to this node
知道如何解决这个错误吗?
【问题讨论】:
-
哪一行导致了错误? “this.model”还是“this.options.parent”?在控制台输出这两个,检查是否定义了
-
line this.model.unbind
-
这意味着,您的视图没有模型,也许它没有被设置或以某种方式被删除。你最好在这个过程之前检查逻辑。
-
您很可能在回调中使用 this.model 并且忘记将该函数绑定到
this