简体   繁体   中英

Sencha Touch - deselect list item?

I'm working on a Sencha Touch application, and have a list of contacts. When a list item is tapped, an ActionSheet is displayed showing some basic functions (such as call, delete and ignore). Unfortunately, when the user taps and the ActionSheet is fired, the List item remains selected underneath the overlay (see the screenshot below):

iOS模拟器的屏幕截图

Here's the function bound to the itemTap event:

itemTap: function(list, index)
{
    // Deselect the selected record:
    var currentRecord = list.getStore().getAt(index);
    currentRecord.forename      = currentRecord.get('forename');
    currentRecord.surname       = currentRecord.get('surname');
    currentRecord.phoneNumber   = currentRecord.get('phoneNumber');
    currentRecord.shortFullName = currentRecord.forename + ' ' +  currentRecord.surname[0];

    list.getStore().deselect(index, true);

    callButton.setText('Call ' + currentRecord.shortFullName + ' (' + currentRecord.phoneNumber + ')');
    unfriendButton.setText('Remove ' + currentRecord.shortFullName + ' as friend');
    friendActionSheet.show();
}

Unfortunately, list.getStore().deselect(index, true) returns the following error: Object [object Object] has no method 'deselect'

Any ideas on what I could be doing wrong, or how I can achieve this?

This works for me:

    listeners: {
        itemtap: function(dv, ix, item, e) {
            // Clear the selection soon
            setTimeout(function(){dv.deselect(ix);},500);
        }
    }

In Sencha Touch 2, use disableSelection: true, while creating a list

Ext.define('App.view.NewsList',{
extend: 'Ext.List',
xtype: NEWS_LIST,

config: {
    store: NEWS_FEED,
    //deselectOnContainerClick: true,// not working in Sencha Touch 2
    disableSelection: true, // since Sencha Touch 2
    itemTpl: '{heading}'
} 
});

如果要清除整个列表:

var selModel = app.views.notesList.deselect(app.views.notesList.getSelectedRecords());

setTimeout is really not a good solution here. It should be like this:

 listeners: {
        itemtap: function(list, ix, item, e) {
            // Clear the selection soon
            list.deselect(list.getSelectedRecords());
        }
    }

this did it for me (sencha touch 2.3):

list = Ext.Viewport.down('nestedlist');
list.getActiveItem().deselectAll();

I haven't tried to recreate your problem but you may want to try:

list.deselect(currentRecord, true);

After you do that you may have to call

doLayout()

or

doComponentLayout()

to refresh the view.

This drove me INSANE.

While the approved answer will work, its worth noting that you can do it with a delay(like nested list does too) like this:

    var selModel = app.views.VideosList.items.items[0].getSelectionModel();
    Ext.defer(selModel.deselectAll, 200, selModel);

I put that in my controller (so its called when the view changes), where app.views.VideosList is my main panel and app.views.VideosList.items.items[0] is the list in that panel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM