1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    41
    Vote Rating
    0
    wasima is on a distinguished road

      0  

    Default 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';

    Code:
    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';     
           
        },
    Pls help me .Thanks in advance

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,673
    Vote Rating
    435
    Answers
    3110
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    41
    Vote Rating
    0
    wasima is on a distinguished road

      0  

    Default


    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.

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    15,102
    Vote Rating
    97
    Answers
    170
    evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold

      0  

    Default


    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!

  5. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    41
    Vote Rating
    0
    wasima is on a distinguished road

      0  

    Default


    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
            }

  6. #6
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,017
    Vote Rating
    23
    Answers
    75
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    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,

    Code:
    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';   
           
        },
    do you have new items like a tab. Then on render or creation register the controller

    Code:
    tab.on('render', function(c){      
          registerNewTab(c);
    });
    Code:
         registerNewTab: function(tab) {     
            this.controllerNameMap[tab.itemId] = 'Summary.DynamicTabController';       
        },

  7. #7
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    15,102
    Vote Rating
    97
    Answers
    170
    evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold evant is a splendid one to behold

      0  

    Default


    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!