1. #1
    Sencha User
    Join Date
    Dec 2012
    Posts
    30
    Answers
    3
    Vote Rating
    0
    Isnogud is on a distinguished road

      0  

    Default Answered: Controller: for every List 1 function?

    Answered: Controller: for every List 1 function?


    Hello,

    I got a list like this with always 4 items:
    Code:
    xtype : 'mylist'                   
    config : {
    type : 'vbox',
    onItemDisclosure : true,
    fullscreen : true,
    store : 'MyStore',
    itemTpl :
    [
    '{name} : {value}'
    ]
    }
    In my controller, I had only one event for the entire list(myList).
    But I want to disclose an item and the controller shows me a specific list(listA, listB...), depending on where I click on it.

    Is there any possibility to do it like this? (just an example)
    Code:
    control : {
    myList: {
    disclose(FirstItem): 'showListA',
    disclose(SecondItem): 'showListB',
    disclose(ThirdItem): 'showListC',
    disclose(FourthItem): 'showListD'
    } 
    }

  2. Quote Originally Posted by ingo.hefti View Post
    I usually do this like that:
    Code:
                xtype:'list',
                title: 'View Selector',
                onItemDisclosure: true,
                store: {
                    data: [
                        { title: 'ListA', xtypeToLoad: 'lista' },
                        { title: 'ListB', xtypeToLoad: 'listb' },
                        { title: 'ListC', xtypeToLoad: 'listc' },
                        { title: 'ListD ', xtypeToLoad: 'listd' }
                    ]
                },
                itemTpl: '{title}'
    Then in my controller I listen for the itemTap and itemDisclose event on that list and push the selected view into a navigation view:
    Code:
     onItemDisclose: function(list, record, target, index ) {
            this.onItemTap(list, index, target, record);
        },
        onItemTap: function(list, index, target, record) {
            var title = record.data.title,
                  viewToPush = record.data.xtypeToLoad,
                  navigationView = list.up('navigationview');
    
    
            navigationView.push({
                title: title,
                xtype: viewToPush,
                data: record.data
            });
    That looks great! I'll try it out later, thanks!

  3. #2
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    71
    Answers
    5
    Vote Rating
    6
    cyee is on a distinguished road

      0  

    Default


    Yes, but what you'd have to do is add logic in to your itemTpl that outputs a specific parameter / attribute for each of the four lists, and then you could use that in your control / ref selector in the controller.

    It's probably easier just to have one main event listener, and in that listener, query the parameters / attributes of the item on which the event was fired. Then proceed from there.

  4. #3
    Sencha User
    Join Date
    Dec 2012
    Posts
    30
    Answers
    3
    Vote Rating
    0
    Isnogud is on a distinguished road

      0  

    Default


    I did it like this:
    Code:
            
    var selectedView = '';
    switch (record.fullName()) {
            case 'ListA':
                selectedView = 'lista';
                break;
            case 'ListB':
                selectedView = 'listb';
                break;
            case 'ListC':
                selectedView = 'listc';
                break;
            case 'ListD':
                selectedView = 'listd';
                break;
          }
                this.getMain().push({
                xtype : selectedView,
                title : record.fullName()
            });
    Code:
        fullName : function() {
            var d = this.data, names = [ d.name ];
            return names.join(" ");
        }
    I know it's probably not the best solution but I'll improve it soon.

  5. #4
    Sencha Premium Member
    Join Date
    Feb 2012
    Location
    Berne, Switzerland
    Posts
    714
    Answers
    41
    Vote Rating
    42
    ingo.hefti has a spectacular aura about ingo.hefti has a spectacular aura about ingo.hefti has a spectacular aura about

      0  

    Default


    I usually do this like that:
    Code:
                xtype:'list',
                title: 'View Selector',
                onItemDisclosure: true,
                store: {
                    data: [
                        { title: 'ListA', xtypeToLoad: 'lista' },
                        { title: 'ListB', xtypeToLoad: 'listb' },
                        { title: 'ListC', xtypeToLoad: 'listc' },
                        { title: 'ListD ', xtypeToLoad: 'listd' }
                    ]
                },
                itemTpl: '{title}'
    Then in my controller I listen for the itemTap and itemDisclose event on that list and push the selected view into a navigation view:
    Code:
     onItemDisclose: function(list, record, target, index ) {
            this.onItemTap(list, index, target, record);
        },
        onItemTap: function(list, index, target, record) {
            var title = record.data.title,
                  viewToPush = record.data.xtypeToLoad,
                  navigationView = list.up('navigationview');
    
    
            navigationView.push({
                title: title,
                xtype: viewToPush,
                data: record.data
            });

  6. #5
    Sencha User
    Join Date
    Dec 2012
    Posts
    30
    Answers
    3
    Vote Rating
    0
    Isnogud is on a distinguished road

      0  

    Default


    Quote Originally Posted by ingo.hefti View Post
    I usually do this like that:
    Code:
                xtype:'list',
                title: 'View Selector',
                onItemDisclosure: true,
                store: {
                    data: [
                        { title: 'ListA', xtypeToLoad: 'lista' },
                        { title: 'ListB', xtypeToLoad: 'listb' },
                        { title: 'ListC', xtypeToLoad: 'listc' },
                        { title: 'ListD ', xtypeToLoad: 'listd' }
                    ]
                },
                itemTpl: '{title}'
    Then in my controller I listen for the itemTap and itemDisclose event on that list and push the selected view into a navigation view:
    Code:
     onItemDisclose: function(list, record, target, index ) {
            this.onItemTap(list, index, target, record);
        },
        onItemTap: function(list, index, target, record) {
            var title = record.data.title,
                  viewToPush = record.data.xtypeToLoad,
                  navigationView = list.up('navigationview');
    
    
            navigationView.push({
                title: title,
                xtype: viewToPush,
                data: record.data
            });
    That looks great! I'll try it out later, thanks!

  7. #6
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    71
    Answers
    5
    Vote Rating
    6
    cyee is on a distinguished road

      0  

    Default


    Quote Originally Posted by ingo.hefti View Post
    I usually do this like that:
    Code:
                xtype:'list',
                title: 'View Selector',
                onItemDisclosure: true,
                store: {
                    data: [
                        { title: 'ListA', xtypeToLoad: 'lista' },
                        { title: 'ListB', xtypeToLoad: 'listb' },
                        { title: 'ListC', xtypeToLoad: 'listc' },
                        { title: 'ListD ', xtypeToLoad: 'listd' }
                    ]
                },
                itemTpl: '{title}'
    Then in my controller I listen for the itemTap and itemDisclose event on that list and push the selected view into a navigation view:
    Code:
     onItemDisclose: function(list, record, target, index ) {
            this.onItemTap(list, index, target, record);
        },
        onItemTap: function(list, index, target, record) {
            var title = record.data.title,
                  viewToPush = record.data.xtypeToLoad,
                  navigationView = list.up('navigationview');
    
    
            navigationView.push({
                title: title,
                xtype: viewToPush,
                data: record.data
            });
    Oh, yes, I see. He's using statically loaded data, so this is a good way to do it.

Thread Participants: 2