javascript ExtJS 数据存储不排序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18492454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 12:08:51  来源:igfitidea点击:

ExtJS data store does not sort

javascriptsortingextjsstore

提问by mrtedweb

I'm using ExtJS 4.2 and created a store with a sorter. The store loads data from a JSONP web service call just fine, but it refuses to sort. Below is a representation of my model, store and load call.

我正在使用 ExtJS 4.2 并创建了一个带有分拣机的商店。存储从 JSONP Web 服务调用加载数据就好了,但它拒绝排序。下面是我的模型、存储和加载调用的表示。

Model:

模型:

Ext.define('Desktop.models.products.DtoProductFamilyModel', {
extend: 'Ext.data.Model',
fields: [
    {
        name: 'ProductFamilyId',
        type: 'string',
        useNull: false,
        defaultValue: Util.getBlankGuid()
    },
    {
        name: 'ParentProductFamilyId',
        type: 'string',
        useNull: true,
        defaultValue: Util.getBlankGuid()
    },
    {
        name: 'BaseItemId',
        type: 'string',
        useNull: true,
        defaultValue: Util.getBlankGuid()
    },
    {
        name: 'Name',
        type: 'string',
        useNull: false,
        defaultValue: ''
    },
    {
        name: 'DisplayName',
        type: 'string',
        useNull: false,
        defaultValue: ''
    },
    {
        name: 'ExternalReferenceId',
        type: 'string',
        useNull: true,
        defaultValue: null
    }
]
});

Store:

店铺:

Ext.define('Desktop.stores.products.GetProductFamiliesStore', {
extend: Ext.data.Store,
model: 'Desktop.models.products.DtoProductFamilyModel',
proxy: {
    type: 'jsonp',
    url: 'http://www.somejsonpwebservice.com',
    method: 'GET',
    pageParam: false, 
    startParam: false, 
    limitParam: false,
    timeout: 9000000,
    noCache: true,
    headers: { 'Content-Type': 'application/json;charset=utf-8' },
    sorters: [{
        property: 'Name',
        direction: 'ASC'
    }],
    sortRoot: 'Name',
    sortOnLoad: true,
    remoteSort: false,
    reader: {
        type: 'json'
    }
}
});

Combobox component utilizing the store:

使用商店的组合框组件:

    {
        xtype: 'combo',
        zzid: 'cmbProductManufacturersFamily',
        store: 'Desktop.stores.products.GetProductFamiliesStore',
        width: 250,
        labelWidth: 50,
        forceSelection: true,
        fieldLabel: Util.translate('Family'),
        emptyText: 'Select Product Family',
        margin: '0 0 0 10',
        displayField: 'Name',
        valueField: 'ProductFamilyId'
    }

Actual call to load store:

实际调用加载存储:

this.stoProductFamilies = this.cmbProductManufacturersFamily.getStore();
this.stoProductFamilies.load()

The data loads just fine, but the store refuses to sort my data. I'm loading over 100 dynamic records into a combobox and need this feature working. If anyone can provide insight as to what I'm doing wrong I would greatly appreciate it.

数据加载得很好,但商店拒绝对我的数据进行排序。我正在将 100 多条动态记录加载到组合框中,需要此功能正常工作。如果有人能提供有关我做错了什么的见解,我将不胜感激。

回答by Andrew Lapham

sortOnLoad, remoteSort and the sorters configurations are not set on the proxy, instead they are set on the store like this:

sortOnLoad、remoteSort 和排序器配置不在代理上设置,而是在商店上设置,如下所示:

Ext.define('Desktop.stores.products.GetProductFamiliesStore', {
    extend: Ext.data.Store,
    model: 'Desktop.models.products.DtoProductFamilyModel',
    sorters: [{
        property: 'Name',
        direction: 'ASC'
    }],
    sortRoot: 'Name',
    sortOnLoad: true,
    remoteSort: false,
    proxy: {
       type: 'jsonp',
       url: 'http://www.somejsonpwebservice.com',
       method: 'GET',
       pageParam: false, 
       startParam: false, 
       limitParam: false,
       timeout: 9000000,
       noCache: true,
       headers: { 'Content-Type': 'application/json;charset=utf-8' },
       reader: {
           type: 'json'
       }
    }
});