2011-03-20 131 views
12

我正在研究一个Sencha Touch应用程序,并有一个联系人列表。当点击一个列表项时,会显示一个显示一些基本功能(如调用,删除和忽略)的ActionSheet。不幸的是,当用户点击和ActionSheet被激发,列表项目仍然覆盖之下选择(见下图):Sencha Touch - 取消选择列表项目?

Screenshot of iOS Simulator

下面是绑定到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'

什么我可以做错了任何想法,或者我怎么能做到这一点?

回答

22

这个工作对我来说:

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

谢谢克里斯,假设你和克里斯一样,在Sencha论坛上为我解决这个问题。它确实有效,我给你一些道具来帮助你! – BenM 2011-03-21 10:03:59

+0

@Chris Thanks :) – Rupesh 2013-12-09 10:06:16

+0

我比下面提到的'disableSelection:true'方法更喜欢这个方法(虽然它很好用),因为这会突出显示用户的选择,然后取消选择它,而'disableSelection'从不突出显示选择到首先。 – 2014-01-16 08:34:53

0

我没有试图重新您的问题,但你可能也想尝试:

list.deselect(currentRecord, true); 

后你做,你可能需要调用

doLayout() 

doComponentLayout() 

刷新视图。

+1

Thanks @ballmw,但'doLayout()'是Container类的一个方法,并且不属于List对象。 'list.refresh()'清除了选择,但也删除了对HCI不利的临时蓝色突出显示... – BenM 2011-03-20 19:02:20

+0

很高兴看到您找到了答案! – ballmw 2011-03-21 11:16:03

0

这驱使我疯了。

虽然批准答案会工作,其值得注意的是,你可以用延迟做(比如嵌套列表确实太)是这样的:

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

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

2

如果要清除整个列表:

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

这工作在一个Ext.dataview.List,除了使用getSelection()而不是getSelectedRecords()。那是与Sencha Touch 2.1。 – 2013-01-04 23:19:44

1

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

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

这似乎不起作用。我首先尝试了这一点。 – Farish 2012-10-23 08:06:37

11

在煎茶触摸2,使用disableSelection:真实,同时创造一个列表

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

如果是**嵌套列表**,也可以使用该选项。但是你必须像下面这样将它添加到'listConfig'属性中:'listConfig:{disableSelection:true}' – 2012-11-29 17:38:55

+0

对于一些nestedList应用程序,你也可以设置'allowDeselect'属性为true。 – 2014-01-16 08:42:43

0

这为我做(煎茶触摸2.3):

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