获取搜索字段的值,然后显示匹配结果sencha touch 2



我在选项卡面板中添加了搜索图标,该面板的导航视图包含停靠在顶部工具栏中的搜索字段。我的问题是,我想从搜索字段中获取值,并将其发送到存储区以查找匹配项。。如果有任何匹配,我希望这些项目显示在searchfield工具栏下面的列表中。我做了很多搜索,但我找不到任何相关的例子来帮助我。任何形式的帮助都将不胜感激。

这是我的看法。。

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] ); 
}

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

store.filter('fieldToSearch', searchPattern);

请参阅此处的文档:http://docs.sencha.com/touch/2.2.1/#/api/Ext.data.Store方法过滤器

另一种选择是store.filterBy(),它将函数作为自变量。如果函数返回true,则该记录将包含在筛选的存储中。文档:http://docs.sencha.com/touch/2.2.1/#/api/Ext.data.Store-method-filterBy

最新更新