-
28 Dec 2011 4:28 PM #1
Reuse Views With Multiple Controllers
Reuse Views With Multiple Controllers
I am trying to reuse views with multiple controllers. The problem I run into is that the controllers are listening to the same view events. Instead of defining views in controller to I do Ext.create() within the controller init function?
-
29 Dec 2011 8:48 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
A controller listens to any event that is fired based on the ComponentQuery selector you provided.
Say you have a form with some checkboxes and you want to do something with the checked event. Since you may have 100 checkboxes but the logic is the same you can use one selector:
That will listen to any checkboxfield that is a child of a formpanel no matter when it is created. So you can remove and add checkboxfields and formpanels all day and this code should still listen to themCode:this.control({ 'formpanel checkboxfield' : { checked : someFn } });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 Dec 2011 9:06 AM #3
So if you have multiple instances of a view the controller should listen to events from all of those instances. If you setup a reference in the controller it should know which instance the event was fired from? So all that too say I could just use the one controller for each instance of those views?
-
29 Dec 2011 9:08 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
Yes, anything that matches that selector will be listened to. The first argument of a listener will be the component firing the event.
I usually don't architect my controllers based on a view... I have controllers based on feature/function. Technically you can have just one controller but that isn't very good application architecture.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 Dec 2011 9:16 AM #5
I am trying to reuse code. I have multiple tabs that serve up similar content ( list > detail ) so the functionality will be the same for each. Would you still create multiple views for each tab of content even though it is the same?
-
29 Dec 2011 9:22 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,582
- Vote Rating
- 433
A tabpanel has to have multiple instances. You can use the same component but separate content. Then your controller action will most likely be the same.
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.


Reply With Quote