有一个 Backbone.js 视图,它有一些特定类的事件。假设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>
比如说 Backbone.js 视图将
//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 events***in Backbone”。没有任何东西对我的条件起作用。当我使用delegate时,内容从DOM中删除。有没有什么方法可以删除特定div下的所有事件,比如“some1”?
P.S:我附上了一张图片,在那里我发生了这个问题。请按照得到确切的idea.
1条答案
按热度按时间v64noz0r1#
您可以使用
undelegateEvents
从视图中删除所有事件侦听器