extjs - How to remove a listener before an event takes place? -
my question similar one: how prevent itemclick event on check change in ext js tree.
however, not provide solution problem. so, question is: how can remove listener before event takes place? problem have 3 listeners in tree, , on checkchange
want prevent itemclick
event. executes in unexpected order. code is:
checkchange:function(node,check){ alert("1"); }, itemclick:function(view,rec,item,index,eventobj){ alert("2"); }, render:function(){ ext.getcmp('mytree').on('checkchange',function(node,check){ alert("0"); ext.getcmp('mytree').removelistener('itemclick',this); }); }
when check node in tree, first see alert(2)
, alert(1)
, alert(0)
. so, code should remove listener happens @ end , want opposite.
edit:
i not want remove itemclick
event. more appropriate word "stop" event, prevent happening.
edit:
the solution e.gettarget() check inside itemclick event. so, code inside itemclick
event looks this:
itemclick:function(view, record, item, index, e, eopts){ if(e.gettarget('span',1,true)){ // other code should take place in case // itemclick event not come checkbox element } }
firstly, it's important understand order events fired:
render
itemclick
checkchange
secondly, it's important understand what's happening within function you've defined render
event.
what code doing adding additional code you've defined checkchange
function, checkchange
when runs alert 1
0
(what seeing). in addition, remove itemclick
listener. mean second time click node, should behave differently.
if want suppress itemclick
event upon render, should un-nest removelistener
call, thus:
render:function(){ this.removelistener('itemclick',this).on('checkchange',function(node,check){ alert("0"); }); }
alternatively, can remove itemclick
event listener itself.
if want change way itemclick
event handled, can intercept event itself, using 1 of these methods:
itemclick:function(view,rec,item,index,eventobj){ eventobj.preventdefault(); //or eventobj.stoppropagation(); //or eventobj.stop(); },
it's not clear you're trying accomplish, however.
Comments
Post a Comment