繁体   English   中英

Sencha Touch - 取消选择列表项?

[英]Sencha Touch - deselect list item?

我正在研究Sencha Touch应用程序,并有一个联系人列表。 当点击列表项时,会显示一个ActionSheet,显示一些基本功能(如调用,删除和忽略)。 不幸的是,当用户点击并触发ActionSheet时,List项目仍然在叠加层下面被选中(参见下面的屏幕截图):

iOS模拟器的屏幕截图

这是绑定到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();
}

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

关于我可能做错了什么的想法,或者我怎么能做到这一点?

这对我有用:

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

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

如果要清除整个列表:

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

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

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

这对我来说(sencha touch 2.3):

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

我没有尝试重新创建您的问题,但您可能想尝试:

list.deselect(currentRecord, true);

完成后,您可能需要打电话

doLayout()

要么

doComponentLayout()

刷新视图。

这让我开始了INSANE。

虽然批准的答案会起作用,但值得注意的是,您可以延迟(如嵌套列表)也可以这样做:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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