2013-07-24 36 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

相关问题