javascript Sencha Touch - 取消选择列表项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5368188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 16:57:58  来源:igfitidea点击:

Sencha Touch - deselect list item?

javascriptsencha-touch

提问by BenM

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):

我正在开发 Sencha Touch 应用程序,并有一个联系人列表。当点击列表项时,会显示一个 ActionSheet,显示一些基本功能(例如调用、删除和忽略)。不幸的是,当用户点击并触发 ActionSheet 时,列表项在覆盖层下方保持选中状态(参见下面的屏幕截图):

Screenshot of iOS Simulator

iOS模拟器截图

Here's the function bound to the itemTap event:

这是绑定到 itemTap 事件的函数:

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'

不幸的是,list.getStore().deselect(index, true)返回以下错误:Object [object Object] has no method 'deselect'

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

关于我可能做错了什么,或者我如何实现这一目标的任何想法?

回答by Chris

This works for me:

这对我有用:

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

回答by Sachin Warke

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

在 Sencha Touch 2 中,使用 disableSelection: true,同时创建列表

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}'
} 
});

回答by Frode

If you want to clear the whole list:

如果要清除整个列表:

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

回答by Swar

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

setTimeout在这里真的不是一个好的解决方案。应该是这样的:

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

回答by Benjamin

this did it for me (sencha touch 2.3):

这是为我做的(sencha touch 2.3):

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

回答by ballmw

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.

刷新视图。

回答by James

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.

我把它放在我的控制器中(所以它在视图更改时调用),其中 app.views.VideosList 是我的主面板,app.views.VideosList.items.items[0] 是该面板中的列表。