在不影响DOM的情况下,从Backbone Js视图中取消绑定事件

zpjtge22  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(133)

有一个 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.

v64noz0r

v64noz0r1#

您可以使用undelegateEvents从视图中删除所有事件侦听器

相关问题