有一个主干 View ,它有一些针对特定类的事件。假设 html 将是这样的。
<div class=""some1">
<a href="#" class="inner1"> Loaction 1 </a>
<a href="#" class="inner2"> Loaction 2 </a>
<a href="#" class="inner3"> Loaction 3 </a>
// All possible hierarchy goes here , like combination of div , a, span
// and every tag has class
// for classes there will be backbone view
<input class="inputclass" type="text"> // input submission
</div>
假设主干 View 将是
//sampleView.js
template: '_SampleHtml',
events: {
"click .inner1": "clickinner1",
"click .inner2": "clickinner2",
"click .inner3": "clickinner3",
"click .inner4": "clickinner4",
...
....
......
"click .inputclass": "inpputclass",
},
clickinner1: function() {
//do something
},
clickinner2: function() {
//do something
},
clickinner3: function() {
//do something
},
clickinner4: function() {
//do something
}
inpputclass: function() {
// if input is having one particular condition
// i want to remove all the events i.e only 'onclick ' should not work on view,
//means even if you click 'Loaction 1 ' , respective event should not occur
// and contents should be present on DOM
}
我试过 "unbind()","off"," stopListening()","委托(delegate) Backbone 中的事件"。没有任何东西符合我的标准。 当我使用委托(delegate)时,内容正在从 DOM 中删除。 有什么方法可以删除特定 div 下的所有事件。像“some1”?
最佳答案
您可以使用 undelegateEvents
从 View 中删除所有事件监听器
关于javascript - 从 Backbone Js View 取消绑定(bind)事件,而不影响 DOM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51768899/