Sencha Touch 过滤器由商店提供

发布于 2024-12-02 15:19:06 字数 1297 浏览 0 评论 0原文

代码:

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

    },

在我的模型中,我有四个字段:

姓名、年龄、性别、特征

我在这里尝试的是:

在页面上的列表中显示数据库的内容,因为列表很长,我想搜索,当用户在搜索字段中写入查询并按下搜索按钮,调用 searchButtonTap 处理程序,该处理程序尝试过滤并显示名称与查询中的名称类似的列表,我也尝试过 filterBy 但这也不起作用。请让我知道出了什么问题?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红玫瑰 2024-12-09 15:19:06

你可以尝试这样:

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

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();
            }
    },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文