2011-03-20 133 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();