开发者

Sencha Touch filterBy the Store

开发者 https://www.devze.com 2023-04-02 07:46 出处:网络
Code:开发者_运维知识库 this.searchField = new Ext.form.Text({ displayField: \'name\', valueField: \'name\',

Code:

开发者_运维知识库
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);

    },

in my models i have four fields:

Name, Age, Sex, Charecteristic

What i am trying over here is:

display the content of my database in a list on the page, since the list is long i wanted to search, when user writes the query in search field and presses the search button, the searchButtonTap handler is invoked which tries to filter and display the list with names similar to the ones in query i also tried filterBy but that too did not work. Please let me know whats wrong?

Thanks.


you can try this way:

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();
            }
    },
0

精彩评论

暂无评论...
验证码 换一张
取 消