Sencha Touch filter通过商店

Ram*_*mar 2 sencha-touch extjs-mvc

码:

this.searchField = new Ext.form.Text({
            displayField: 'name',
            valueField: 'name',
            editable: true,
            forceSelection: true,
            triggerAction: 'all',
            emptyText: 'Search...',
            selectOnFocus: true
    });

this.searchButton = new Ext.Button({// The button press will invoke the search action
        text: 'Go',
        handler: this.searchButtonTap,
        scope: this
    });

    this.topToolbar = new Ext.Toolbar({
                   items: [
                { xtype: 'spacer' },    
                    this.searchField,
                    this.searchButton,
                    { xtype: 'spacer' },
                ]
        });

searchButtonTap: function () {

        var searchText = this.searchField.getValue();
        console.log(searchText);
        //console.log(this.myappsList.store.getCount());
        console.log(this.myappsList.store.filter('name', searchText));
        //this.myappsList.store.filter(searchText);

    },
Run Code Online (Sandbox Code Playgroud)

在我的模型中,我有四个领域:

姓名,年龄,性别,Charecteristic

我在这里尝试的是:

在页面上的列表中显示我的数据库的内容,因为列表很长我想搜索,当用户在搜索字段中写入查询并按下搜索按钮时,searchButtonTap 调用处理程序,尝试过滤并显示列表类似于查询中的名称我也尝试过,filterBy但这也没有用.请让我知道什么是错的?

谢谢.

wha*_*atf 5

你可以尝试这种方式:

searchButtonTap: function () {
        var searchTerm = this.searchField.getValue();
        if (searchTerm) {
            this.myappsList.store.filterBy(function(record){
            var fieldData = record.data.city.toLowerCase().indexOf(searchTerm);
            if (fieldData > -1 ) 
                return record;
            });


        }
        else {
            this.myappsList.store.clearFilter();
            }
    },
Run Code Online (Sandbox Code Playgroud)