-
8 Nov 2011 10:46 AM #1
Unclear how to implement afteritemchange listener
Unclear how to implement afteritemchange listener
I have a tabpanel and I would like to implement the afteritemchange event listener but not clear where to do so and cannot find examples.
I thought this would work but I am missing something. Also - my goal is to destroy panel as they are changed - It seems the afteritemchange has issues with animation (saw on another forum) - not sure if that is best approach for my goal?
Code:Ext.define('App.view.Main', { extend: 'Ext.tab.Panel', xtype: 'main', config: { activeTab: 0, fullscreen: true, flex: 1, layout: { animation: { type: 'slide', duration: 250 } }, tabBar: { layout: { pack : 'center', align: 'center' }, docked: 'bottom', scrollable: { direction: 'horizontal', indicators: false } }, items: [ ... ], listeners: { activeitemchange: function(a, b, c, d) { alert('f'); } } } });
-
8 Nov 2011 1:51 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Is it firing? If not, try putting it where you instantiate the view and put the listener there.
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.
-
9 Nov 2011 7:01 AM #3
Actually seems that listeners are not accepted on component definition, however, if you add your listeners on component creation, they works great.
Take a look at your edited code:
Hope this helps.Code:Ext.Loader.require(['Ext.*']); Ext.application({ name: 'App', launch: function() { Ext.define('App.view.Main', { extend: 'Ext.tab.Panel', alias: 'widget.main', config: { activeTab: 0, fullscreen: true, flex: 1, layout: { animation: { type: 'slide', duration: 250 } }, tabBar: { layout: { pack : 'center', align: 'center' }, docked: 'bottom', scrollable: { direction: 'horizontal', indicators: false } }, items: [ { title: 'first', iconMask: true, iconCls: 'star', html: '1' }, { title: 'second', iconMask: true, iconCls: 'star', html: '2' } ], } }); Ext.widget('main',{ listeners: { activeitemchange: function(a, b, c, d) { alert('changed'); } } }); } });Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
12 Nov 2011 4:26 PM #4
I HOPE that this is a bug. Surely we should be able to continue to add listeners in definitions right? Has this bug already been reported?
Twitter: lylepratt
-
12 Nov 2011 7:05 PM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
Code:constructor: function(config) { this.callParent(arguments); this.on('event', this.someFunction, this); }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.
-
12 Nov 2011 7:30 PM #6
Thanks for the tip Mitchell. I've already implemented something similar in a new project for now. However, the reason why I consider it a bug is because many people, including my self have thousands of lines of code written which rely on being able to configure listeners in definitions. I understand it may not be implemented yet, but I hope it will be by the general release.
Twitter: lylepratt
-
13 Nov 2011 6:19 AM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
I disagree that this is a bug. It's not a good idea to use the listeners property in a definition as when you instantiate that class and use the listeners as a config, the listeners property you used when you defined the class will now be overwritten and not used and that could break your class if you depend on those listeners.
this.on is the proper way to add listeners when defining a class.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.
-
13 Nov 2011 8:47 AM #8
I think that's a matter of preference, but if that is the official response then the documentation needs to be changed. The documentation lists "listeners" as a configuration option.
Twitter: lylepratt
-
13 Nov 2011 8:57 AM #9Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
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.
-
13 Nov 2011 11:50 AM #10
Why should that work with Ext.create and NOT Ext.define?
Twitter: lylepratt


Reply With Quote