-
21 Feb 2012 2:46 AM #1
call controller function
call controller function
I have a controller defined like this:
How can i call the showTest() function? I tried this:PHP Code:Ext.define('MyApp.controller.TestController', {
extend: 'Ext.app.Controller',
config: {
},
showTest: function() {
alert('aaa');
}
});
MyApp.controller.TestController.showTest();
But this doesn't work. Anyone any idea how to do this..??
-
21 Feb 2012 8:07 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,623
- Vote Rating
- 434
Where do you want to call it from? If from a view the view should not have that logic, the controller should act on events from the view.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
22 Feb 2012 5:15 AM #3
I want to call it from a DataView. I'm not using any Ext buttons or field on which i can add an event. I have a DIV with an onclick, like this:
<div onclick="myController.myFunc({Username})">{Username}</div>
These DIVs are generated by JSON data (from a store). I want to call my controller function directly from that DIV. Is that possible...??
-
22 Feb 2012 5:24 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,623
- Vote Rating
- 434
You should fire a custom event in the tap listener on the <div>. Your controller then can listen for the custom event.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
15 May 2012 9:03 AM #5
-
15 May 2012 9:15 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,623
- Vote Rating
- 434
To listen for tap on an element:
The delegate config can accept any dom selector (like div.myclass)Code:component.element.on({ scope : component, delegate : 'div', tap : function(e) {} });
To fire a custom event (like in the tap function) you can do:
No win the controller you can listen to the divtap event on the componentCode:this.fireEvent('divtap', this, e.getTarget());Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
21 May 2012 6:17 AM #7
Thanks for you help but I am still facing problem to fire a custom tap event on a div. I am trying to set a custom tap event against a div at Ext.define but it doesn't work. Actually i m not sure what to do on view level and what to do on controller level. I tried all possible variations and also read your other posts but it didn't solve my problem. Kindly give some full example which implements 'tap event on an element'. It will be great help for me. Thanks
-
23 May 2012 5:20 AM #8
-
25 May 2012 3:23 AM #9
I done this. If you press button, then the handler call the controller. This very simply! Use this.
tsvb2 - name of app,tsvb2.app.getController('tsvb2.controller.playerEdit').editPlayer(0);
app - must not forget


Reply With Quote