-
26 Jan 2013 10:15 AM #1
Answered: tap event on a dinamically created custom Panel (MVC)
Answered: tap event on a dinamically created custom Panel (MVC)
Hi coders, I have a problem about views and events.
I have to put dinamically some custom Panels in my app (xtype:'card').
I want my Controller to manage events on these Panels, with "refs".
Sample code:
The event simply doesn't work!Code:Ext.define('D45.controller.Deck', { extend: 'Ext.app.Controller', config: { ... refs: { desk: '#desk', card: 'card' }, control: { card:{ tap: function(){ Ext.Msg.alert('tap!'); } }, ... putCard: function(id){ this.getDesk().add({ xtype:'card', cardNo:id }); } });
Have you got some ideas?
-
Best Answer Posted by mitchellsimoens
refs only support a single instance.
Like I said, you can easily add a tap event to the panel's element and then have it listenable in the controller. Here is an example:
Code:Ext.define('Test.controller.Main', { extend : 'Ext.app.Controller', config : { control : { 'test-mypanel' : { tap : 'onPanelTap' } } }, onPanelTap : function(panel) { console.log('panel was tapped on', panel); } }); Ext.define('Test.view.MyPanel', { extend : 'Ext.Panel', xtype : 'test-mypanel', initialize : function() { this.callParent(arguments); this.relayEvents(this.element, ['tap']); } }); Ext.application({ name : 'Test', controllers : [ 'Main' ], launch : function () { Ext.Viewport.setActiveItem({ xtype : 'test-mypanel', html : 'Tap on me and look at the console' }); } });
-
28 Jan 2013 7:07 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
In the API docs does the component list a tap event? If not, why did you think it'd work? You can fire the event from the view as you would need to add an element event listener.
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.
-
28 Jan 2013 1:28 PM #3
-
28 Jan 2013 1:31 PM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
Ext.Panel does not have a tap event listed in the API docs.
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.
-
29 Jan 2013 1:28 PM #5
Oh... I feel stupid...
but...
I changed "extend: 'Ext.Panel'," into "extend: 'Ext.Button',"... nothing changed!
Also if i use this:
D45.app.getController('Deck').getCard()
It returns only one "Card"... i expected to return an Array of Cards...
And if I set an event on it:
D45.app.getController('Deck').getCard().onTap(function(a){alert(a);})
It doesn't work.
What am I doing wrong?
-
29 Jan 2013 1:35 PM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
refs only support a single instance.
Like I said, you can easily add a tap event to the panel's element and then have it listenable in the controller. Here is an example:
Code:Ext.define('Test.controller.Main', { extend : 'Ext.app.Controller', config : { control : { 'test-mypanel' : { tap : 'onPanelTap' } } }, onPanelTap : function(panel) { console.log('panel was tapped on', panel); } }); Ext.define('Test.view.MyPanel', { extend : 'Ext.Panel', xtype : 'test-mypanel', initialize : function() { this.callParent(arguments); this.relayEvents(this.element, ['tap']); } }); Ext.application({ name : 'Test', controllers : [ 'Main' ], launch : function () { Ext.Viewport.setActiveItem({ xtype : 'test-mypanel', html : 'Tap on me and look at the console' }); } });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.
-
30 Jan 2013 2:40 PM #7
Great!
So the key is the function "relayEvents".
Thank you very much!


Reply With Quote