javascript - dojo how to overwrite event handler -
Currently, the dojo uses the When the button is clicked it will call the attached function. However, according to the documents, the removal of existing handlers should be done in the following manner It is not the way I want to delete the event handler. I do not handle handler anywhere but I want to add a new 'click' event Change the existing 'click' event handler and add a new one. What do I want to achieve? Thank you! It is not possible, the framework refers to an event handler, as it does with jQuery's other frameworks are equal. There is a mechanism to remove all event handlers using the For example, you can wrap it inside a new module: and then you can use it: It should work fine, as you can see in this Bela: on method to connect the event to the Hyndere.
BTN = new button (); Btn.on ('click', function () {console.log ('do something');});
handler = btn.on ('click', function () {console. Log ('do something');}); Handler.remove ();
btn.on ('click', function () {console. Log ('do something different');});
off function in the jQuery course, but it is not available in dojo. Chris Heze's comments have been suggested, so you can use aspects like this by wrapping this feature in any other module or on the
dojo / on module.
// event handler var 2 On = function (dom, event, callback) {On2.handlers = []; If (at 2.handlers [incident] === undefined) {on2.handlers [event] = []; } Var Handler = On (Dome, Event, Callback); On2.handlers [Event] Push ({node: dom, handler: handler}); Returnee; }; // close functionality lang.mixin (on2, on, {close} function (dom, event) {if (this handlers [event]! == undefined) {array.forEach (this.handlers [event], function (handler) ) {If (handler.node === dom) {handler.handler.remove ();}}}}}}});
on2 (dom.byId ("test"), "click", function () {Console.log ("test 1 2 3"); // old event handler}); On2.off (dom.byId ("test"), "click"); // Delete old event handlers 2 (dom.byId ("test"), "click", function () {console.log ("test 4 5 6"); // new event handler});
Comments
Post a Comment