PDA

View Full Version : My tap event listener function is executed on app launch!



eilijah
2 Nov 2011, 4:05 PM
Hello,

here my controller :

Ext.define('s2Test.controller.Main', {
extend: 'Ext.app.Controller',

views: [
'Home',
'Tabgroup'
],

init: function() {

this.control({
'#menuButton456': {
// Why this function is executed on the app loading?
tap: this.onMenuButtonTap(),
}
});

Ext.apply( s2Test.views, {
home: this.getHomeView().create(),
tabgroup: this.getTabgroupView().create(),
});

var Ivs = s2Test.views;
s2Test.ideoviewport.add([
Ivs.home,
Ivs.tabgroup
]);

s2Test.ideotoolbar.setItems([{
xtype: 'button',
id: 'menuButton456',
text: 'menu',
ui: 'right'
}]);
s2Test.ideotoolbar.setTitle("Home");

Ivs.home.show();
},

onMenuButtonTap: function () {
alert("tap");
this.application.fireEvent('loadContent');
}


});

The 'alert("tap");' is executed when i launch the application, how is it possible?

There, my full small test app :
- app.js : http://pastebin.com/ggC9ZjSK
- controller/Main.js : http://pastebin.com/C35PLfH8
- controller/TabGroup.js: http://pastebin.com/QmPv6PTf
- view/Home.js: http://pastebin.com/L9gsX3ny
- view/TabGroup.js : http://pastebin.com/tqF9mZ5s

PS: any comment on the code is welcome.

Good night!

AndreaCammarata
3 Nov 2011, 1:08 AM
Hi.
You simply need to remove the brackets on your tap handler like follows:



this.control({
'#menuButton456': {
tap: this.onMenuButtonTap,
}
);


Hope this helps.

eilijah
7 Nov 2011, 2:54 PM
Thank you!

this just works fine :

this.control({ '#menuButton': {
tap: this.onMenuButtonTap,
}
});