-
12 Nov 2012 1:52 AM #1
Unanswered: Mapping array contents to default controller
Unanswered: Mapping array contents to default controller
hi all,
i have a method here i do mapping of a tab name to a specific controller, for some tabs i have mapped corresponding controller , i want something like " for all the other tabs map 'Summary.DynamicTabController' as the default controller " .
something like : this.controllerNameMap['all_other_tabs'] = Summary.DynamicTabController';
Pls help me .Thanks in advanceCode:createControllerMap: function() { this.controllerNameMap = new Array(); this.controllerNameMap['Summary'] = 'Summary.SummaryController'; this.controllerNameMap['Equipment'] = 'Equipment.EquipmentController'; this.controllerNameMap['Traffic'] = 'Traffic.TrafficController'; this.controllerNameMap['Client'] = 'Client.ClientController'; this.controllerNameMap['RF'] = 'RF.RFController'; this.controllerNameMap['NewTab1'] = 'Summary.DynamicTabController'; },
-
13 Nov 2012 5:44 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,684
- Vote Rating
- 435
- Answers
- 3111
So why don't you just have a default mapping? I'm sorry, not really understanding what you are doing or why you can't have a default?
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 2012 9:33 PM #3
Hi, Mitchell Simoens,
Let me try explaining the problem.
What i mean is i have 5 tabs(Summary,Equipment,Traffic,Client,RF) in my tab panel which are static , now i have an add button in tab panel on clicking which new tabs get added dynamically like NewTab1,NewTab2 etc, to these newly added tabs i need to specify which controller they are mapped to , for all the dynamically added tabs the controller is same 'Summary.DynamicTabController' for all the other 5 static tabs i have specified their controller names manually in this function, so i need to tell this function that if you don't get tab names from one of these 5 static tab names you map the tab name to the default controller that is 'Summary.DynamicTabController'.
Hope you understood the issue now.
-
13 Nov 2012 10:09 PM #4Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,103
- Vote Rating
- 97
- Answers
- 170
You can just check if the name exists:
Code:var map = { summary: 'foo', equipment: 'bar' }; var a = 'summary'; var b = 'notthere'; if (map[a]) { console.log(map[a]); } if (!map[b]) { //default; }Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
13 Nov 2012 11:26 PM #5
Thanks evant,
but newly added tabs have different names like NewTab1,NewTab2 etc.that are generated dynamically .. I cant fix it to just 'nothere' and do mapping .
Code:createControllerMap: function() { this.controllerNameMap = new Array(); var map = { Summary: 'Summary.SummaryController', Equipment: 'Equipment.EquipmentController', Traffic : 'Traffic.TrafficController', Client : 'Client.ClientController', RF : 'RF.RFController' }; var a = 'Summary'; var b = 'notthere'; if (map[a]) { console.log(map[a]); this.controllerNameMap['Summary'] = 'Summary.SummaryController'; this.controllerNameMap['Equipment'] = 'Equipment.EquipmentController'; this.controllerNameMap['Traffic'] = 'Traffic.TrafficController'; this.controllerNameMap['Client'] = 'Client.ClientController'; this.controllerNameMap['RF'] = 'RF.RFController'; } else { this.controllernamemap['nothere'] = 'summary.DynamicTabController'; // cant do this 'nothere' can be NewTab1,NewTab2 etc }
-
14 Nov 2012 12:25 AM #6Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,017
- Vote Rating
- 23
- Answers
- 75
I do not see what you want. What is createControllerMap? When is it called?
But...when registering dynamically new items the most common way is. First register your static stuff in a register
like you did initial,
do you have new items like a tab. Then on render or creation register the controllerCode:createControllerMap: function() { this.controllerNameMap = new Array(); this.controllerNameMap['Summary'] = 'Summary.SummaryController'; this.controllerNameMap['Equipment'] = 'Equipment.EquipmentController'; this.controllerNameMap['Traffic'] = 'Traffic.TrafficController'; this.controllerNameMap['Client'] = 'Client.ClientController'; this.controllerNameMap['RF'] = 'RF.RFController'; },
Code:tab.on('render', function(c){ registerNewTab(c); });Code:registerNewTab: function(tab) { this.controllerNameMap[tab.itemId] = 'Summary.DynamicTabController'; },
-
14 Nov 2012 12:55 AM #7Sencha - Ext JS Dev Team
- Join Date
- Apr 2007
- Location
- Sydney, Australia
- Posts
- 15,103
- Vote Rating
- 97
- Answers
- 170
That's the point. You declare a map of existing names/controllers.
If it doesn't exist in the map, then you know to use the default controller.Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!


Reply With Quote