1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    26
    Vote Rating
    1
    camdagr8 is on a distinguished road

      0  

    Default LIST: Get selected index on swipe

    LIST: Get selected index on swipe


    I'm trying to get the selected of a list when you swipe it. I'd like to make sure the list item is selected before executing a function on the list item but I can't for the life of me figure out how to do this! Here's my code, please help!!!!

    Code:
    {
        xtype: 'list',
        flex: 1,
        indexBar: true,
        itemTpl: '{city} {name}',
        store: 'TeamStore',
        id: 'TeamsList',
        items: [
            {
                xtype: 'toolbar',
                docked: 'bottom',
                height: 49,
                cls: 'z-tabbar',
                items: [
                    {xtype: 'searchfield', name: 'teamSearch', placeHolder: 'Search', centered: true, width: '95%'}
                ]
            }                
        ],
        listeners: {
            itemswipe: function (list, idx, target, record, evt) {
                
                var selected = list.getActiveItem();
                console.log(list.getActiveItem());
                if (!selected) { return; }
                
                var selectedIndex = selected[0];
                console.log([selectedIndex, idx]);
                Ext.Msg.alert('itemswipe', idx);
    
    
            } // itemswipe
        } // listeners                
    }

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    34,117
    Vote Rating
    453
    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 mitchellsimoens has much to be proud of

      0  

    Default


    I'm curious why you tried getActiveItem() to get the selected?

    To get the selection you should use getSelection() instead
    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
    Aug 2011
    Posts
    26
    Vote Rating
    1
    camdagr8 is on a distinguished road

      0  

    Default


    Mainly because the swipe event isn't fired on the actual selection at the time. For instance if you select item 1 but swipe item 3, the event is fired on item 3 not selection. My functionality requires that the item be selected before doing anything with the swipe event. So I need to check and find out what the selected index is before doing anything.

    Also I get this back in the xcode debugger:
    JSON.stringify cannot serialize cyclic structures.

    And the documentation doesn't explain what getSelection() outputs.

    So ultimately what I ended up doing was using jquery's .each function and search the list for the 'x-item-selected' class and matched that against the swipe event index like so:

    Code:
    var selected = false;
    var listID = '#' + list.getId();
    $(listID + ' .x-list-item').each(function (index, element) { if ($(this).hasClass('x-item-selected') && index == idx) { selected = true; } });
    if (!selected) { return; }

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    34,117
    Vote Rating
    453
    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 mitchellsimoens has much to be proud of

      0  

    Default


    Why not do list.getSelection() in the swipe event listener. According to the docs, getSelection does:

    Returns an array of the currently selected records.
    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.

Tags for this Thread