【问题标题】:Sencha Touch list store disable sortingSencha Touch 列表商店禁用排序
【发布时间】:2017-08-13 17:40:16
【问题描述】:

我的列表正在从 php 服务获取数据,收到的数据按我需要的顺序排列。但是 sencha 会自动按字母顺序对我的列表进行排序。 以下是我的代码:

Ext.define('MyList', {
    extend: 'Ext.dataview.List',

    config:     {
        grouped: true,
        plugins: [
            {
                xclass:          'Ext.plugin.PullRefresh',
                pullRefreshText: 'Pull down to refresh'

            },
            {
                xclass:     'Ext.plugin.ListPaging',
                autoPaging: true,
                noMoreRecordsText: 'No More Records'

            }
        ]
    },
    initialize: function () {
        this.callParent(arguments);
        var store = Ext.create('Ext.data.Store', {

            pageParam: 'page',
            grouper: {
                groupFn: function (record) {
                    return record.data.group_label;
                }
            },
            model:   'ListItem',
            proxy:   {
                type:   'ajax',
                url:    '/m/services/activity_list_items.php',
                reader: {
                    type:         'json',
                    rootProperty: 'root.results'
                }
            }
        });

        var template = Ext.create('GenericListItem', {
            hascounts: true,
            hasicon:   true,
            varmap:    {
                descr:  'subtext',
                count:  'sub_item_cnt',
                itemid: 'itemid',
                uniqid: 'uniqid'
            }
        });

        var emptyText = 'Recent Activity Items';
        this.setStore(store);
        this.setItemTpl(template);
        this.setEmptyText(emptyText);
    }
});

如何避免列表自动排序?

【问题讨论】:

    标签: list sencha-touch-2


    【解决方案1】:

    将以下内容添加到您的商店配置中。

    remoteSort : true,
    

    remoteSort 在 sencha 中默认为 false。所以 sencha 在客户端自动排序。查看链接了解更多详情http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Store-cfg-remoteSort

    【讨论】:

    • 谢谢,很好的解决方案!
    【解决方案2】:

    删除这个:

    grouped: true
    

    如果您不想为每个项目添加标题并强制删除它,请从您的列表配置中删除:

    grouper: {
        groupFn: function (record) {
            return record.data.group_label;
        }
    }
    

    来自您的商店,因为基本上在您的情况下,grouper 属性用于根据您的 group_label 字段按字母顺序对您的项目进行分组。希望对你有帮助:)

    【讨论】:

    • 也许他仍然希望将它们分组,但不排序?
    • 是的,我想根据group_label进行分组,但不排序。
    猜你喜欢
    • 2012-06-17
    • 2011-09-01
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    相关资源
    最近更新 更多