2

コード:

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

    },

私のモデルでは、4 つのフィールドがあります。

名前、年齢、性別、特徴

私がここで試しているのは次のとおりです。

ページのリストにデータベースのコンテンツを表示します。リストが長いため、検索したかったのですが、ユーザーが検索フィールドにクエリを記述して検索ボタンを押すと、searchButtonTap ハンドラーが呼び出され、リストをフィルタリングして表示しようとしますクエリの名前に似た名前も試しfilterByましたが、それも機能しませんでした。何が悪いのか教えてください。

ありがとう。

4

1 に答える 1

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();
            }
    },
于 2011-09-02T22:59:51.637 に答える