2013-07-24 31 views
0

我將搜索圖標添加到了我的選項卡面板,該面板的導航視圖包含工具欄停靠的頂部的搜索字段。我的問題是我想從搜索字段中取值並將其發送到商店以查找匹配..如果有任何匹配,我希望這些項目將顯示在searchfield工具欄下方的列表中。我做了很多搜索,但我無法找到任何有助於我的相關示例。任何形式的幫助,將不勝感激。獲取搜索字段的值,然後顯示匹配結果sencha touch 2

這是我的看法..

items: [{ 
    xtype: 'toolbar', 
    docked: 'top', 
    style: 'background:darkgray', 
    items: [{ 
      xtype: 'searchfield', 
      placeHolder: 'Search... ' 
    }, { 
      xtype: 'button', 
      iconCls: 'search', 
      iconMask: true, 
      ui: 'confirm', 
      action: 'search-app' 


    }] 
}, {//here I want to show my filtered data 
    xtype: 'list', 
    itemId: 'searchlist', 
    store: 'SearchItemStore', 
    onItemDisclosure: true, 
    emptyText: 'No data found!', 
    itemTpl: '{Name}' 
}] 

在我的控制,我呼籲按鈕,添加功能是這樣的:

mySearchFunction: function(element , e, eOpts) { 
    var searchPattern = this.getSearchFieldAction().getValue(); 
    var store = Ext.getStore('ProductStore'); 
    // here I want to set the param that has to send to the store proxy..I am really not sure how this works 
    store.find(fieldName, value, [startIndex], [anyMatch], [caseSensitive], [exactMatch]); 
} 
+0

您使用的是MVC嗎?如果是這樣,你如何控制搜索按鈕被點擊時發生的情況? – kevhender

回答

0

你要找的是store.filter()方法。

store.filter('fieldToSearch', searchPattern); 

查看該文檔這裏:http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.Store-method-filter

另一個替代方案是store.filterBy(),這需要一個函數作爲參數。如果函數返回true,則該記錄包含在過濾的商店中。 Docs:http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.Store-method-filterBy

+0

謝謝..它正在工作,但列表正在加載所有數據,然後它正在該列表中搜索..我不希望列表顯示任何數據之前搜索,當我們給的價值,那麼它應該顯示過濾的數據..你有什麼想法嗎? – GiGi

+0

你什麼時候加載你的商店?商店中是否有「autoLoad」? – kevhender

+0

我沒有使用按鈕..我正在使用searchfield keyup,以便每個字母開始過濾..所以第一次它工作正常,但第二次當我們開始輸入字母它顯示所有數據存儲= this.getSearchList( ).getStore();這是我在控制器中使用的 \t \t store.load(); \t \t store.filter('DESCRIPTION',filterPattern); – GiGi

相關問題