Javascript 主干js中的this.unbind与this.el.unbind有什么区别
我在主干视图和Javascript 主干js中的this.unbind与this.el.unbind有什么区别,javascript,backbone.js,Javascript,Backbone.js,我在主干视图和this.destoryview()方法中绑定了一些事件,我调用了this.unbind()。但这并不是解开束缚的事件。当某个事件发生时,它两次调用有界方法 然后我通过this.$el.unbind()调用this.unbind()来更改this.unbind(),然后它就可以正常工作了 events:{ 'click #closeButton' : 'clearSearch', // some events }, initiali
this.destoryview()
方法中绑定了一些事件,我调用了this.unbind()
。但这并不是解开束缚的事件。当某个事件发生时,它两次调用有界方法
然后我通过this.$el.unbind()
调用this.unbind()
来更改this.unbind()
,然后它就可以正常工作了
events:{
'click #closeButton' : 'clearSearch',
// some events
},
initialize: function(options){
this.container = options.container;
},
render: function() {
if(this.oSearchContext.isAdvancedSearchEnabled() == true)
{
this.$el.html(this.advancedSearchSummaryViewTemplate);
}
else
{
this.$el.html(this.advancedSearchTemplate);
}
this.container.append(this.$el);
},
使用this.unbind()的destroyView方法
你能给我解释一下这两种方法的区别吗。我建议使用的是's
listenTo
,而不是使用bind
:
view.listenTo(model, 'change', view.render);
一旦
视图
被销毁,所有绑定将自动删除(取消绑定) 您可以使用视图.bind
(或现代视图.listenTo
或视图.on
)订阅另一个主干组件,例如侦听主干模型中的更改事件
您可以使用view.$el.bind
(或现代view.$el.on
)来监听DOM中的用户交互
同样的逻辑适用于unbind
或现代off
语法和API相似,用途不同。事件绑定类似于
“单击#关闭按钮”:“clearSearch”
也在代码中编辑。
view.listenTo(model, 'change', view.render);