backbone.js stoplistening事件

本文概述

  • 参数说明
Backbone.js事件stopListening方法:
句法:
object.stopListening(other, event, callback)

参数说明其他:用于定义另一个对象的名称。
事件:用于绑定对象。
【backbone.js stoplistening事件】回调:它是对代码的引用,并以对象作为上下文进行调用。
让我们举个例子。
请参阅以下示例:
< !DOCTYPE html> < head> < title>Event stopListening Example< /title> < script src="http://img.readke.com/220416/011002F95-0.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/0110024525-1.jpg" type="text/javascript">< /script> < script src="http://img.readke.com/220416/0110022211-2.jpg" type="text/javascript">< /script> < /head> < body> < script type="text/javascript">//Create an object 'myVal' and 'myVal1' and extend them using Backbone.Events method var myVal = _.extend({name:'Hello..'}, Backbone.Events); var myVal1 = _.extend({name:'Welcome to srcmini'}, Backbone.Events); //created the 'listenMe' callback function and invoked when one object listens to particular event on another object var listenMe = function(){ document.write("The value is: "); document.write(this.name); }; //The object 'myVal1' listens once for the 'listenMe' event triggered on object 'myVal' myVal1.listenTo(myVal, 'listenMe', listenMe); //The 'myVal' has no 'listenMe' event and display the value of 'myVal1' myVal.trigger('listenMe'); //The 'myVal1' stops listening to specific event on 'myVal' and displays nothing myVal1.stopListening(myVal, 'listenMe'); myVal.trigger('listenMe'); < /script> < /body> < /html>

输出:
将以上代码保存在stoplistening.html文件中,然后在浏览器中打开此文件。
backbone.js stoplistening事件

文章图片

    推荐阅读