-
10 May 2012 4:38 AM #1
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 }
-
14 May 2012 5:44 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,117
- Vote Rating
- 453
I'm curious why you tried getActiveItem() to get the selected?
To get the selection you should use getSelection() insteadMitchell 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.
-
14 May 2012 8:23 PM #3
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; }
-
15 May 2012 5:12 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,117
- Vote Rating
- 453
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.


Reply With Quote