mercredi 2 juillet 2014

Single fire event listener, config defined style vs. .on() / .un()

I'm having problems getting a tap.Panel to set the default tab to the one in index 0. For whatever reason, setting the activeTab config is having no effect. I've tried numerous event listeners and the only one that works is afterlayout. The thing about that is(and I'm kinda just assuming here), with that listener I now cant navigate away from the 0 tab. I'm assuming that every time I hit another tab, its calling afterlayout, and then setting it back to the 0 tab.

So in my tab.Panel definition, I want to do something like this:



Code:



listeners: {
afterlayout: function() {
this.setActiveTab(0);
this.un('afterlayout', fn??);
}
},

My question is, how do I set the fn reference that is required for unregistering listeners?

Maybe this is the wrong way to do this.


I know I could just add a listener right before I show this panel using '.on()' and '.un()', which I may do, but I was curious if the first solution was possible or not recommended?


Would below be the best way to go about this single fire listener task?



Code:



var fn = function() {
tabView.setActiveTab(0);
tabView.un('afterlayout', fn);
}
tabView.on('afterlayout', fn);

Bonus curiosity question...

What if I did it like this:



Code:



tabView.on('afterlayout', function() {
tabView.setActiveTab(0);
tabView.un('afterlayout', ???); <---
});

How would I reference that function that is directly passed when I want to remove the listener from within the function itself?

Thanks!





Aucun commentaire:

Enregistrer un commentaire