Extjs JsonStore和JsonReader存在问题

Extjs JsonStore和JsonReader存在问题,extjs,jsonreader,Extjs,Jsonreader,在我的ExtJS应用程序中,我使用EditorGridPanel显示来自服务器的数据 var applicationsGrid = new Ext.grid.EditorGridPanel({ region: 'west', layout: 'fit', title: '<img src="../../Content/img/app.png" /> Приложения', collapsible: true, margins: '0 0 5

在我的ExtJS应用程序中,我使用EditorGridPanel显示来自服务器的数据

var applicationsGrid = new Ext.grid.EditorGridPanel({
    region: 'west',
    layout: 'fit',
    title: '<img src="../../Content/img/app.png" />  Приложения',
    collapsible: true,
    margins: '0 0 5 5',
    split: true,
    width: '30%',
    listeners: { 'viewready': { fn: function() { applicationsGridStatusBar.setText('Приложений: ' + applicationsStore.getTotalCount()); } } },
    store: applicationsStore,
    loadMask: { msg: 'Загрузка...' },
    sm: new Ext.grid.RowSelectionModel({
        singleSelect: true,
        listeners: { 'rowselect': { fn: applicationsGrid_onRowSelect} }
    }),
    viewConfig: { forceFit: true },
    tbar: [{
        icon: '../../Content/img/add.gif',
        text: 'Добавить'
    }, '-', {
        icon: '../../Content/img/delete.gif',
        text: 'Удалить'
    }, '-'],
    bbar: applicationsGridStatusBar,
    columns: [{
        header: 'Приложения',
        dataIndex: 'ApplicationName',
        tooltip: 'Наименование приложения',
        sortable: true,
        editor: {
            xtype: 'textfield',
            allowBlank: false
        }
    }, {
        header: '<img src="../../Content/img/user.png" />',
        dataIndex: 'UsersCount',
        align: 'center',
        fixed: true,
        width: 50,
        tooltip: 'Количество пользователей приложения',
        sortable: true
    }, {
        header: '<img src="../../Content/img/role.gif" />',
        dataIndex: 'RolesCount',
        align: 'center',
        fixed: true,
        width: 50,
        tooltip: 'Количество ролей приложения',
        sortable: true}]
    });
我相信问题在于我不使用reader,但当我使用JsonReader时,网格会停止显示任何数据

var applicationReader = new Ext.data.JsonReader({
    root: 'applications',
    totalProperty: 'total',
    idProperty: 'ApplicationId',
    messageProperty: 'message',
    fields: [{ name: 'ApplicationId' }, { name: 'ApplicationName', allowBlank: false }, { name: 'UsersCount', allowBlank: false }, { name: 'RolesCount', allowBlank: false}]
});

var applicationsStore = new Ext.data.JsonStore({
    id: 'app1234',
    proxy: new Ext.data.HttpProxy({
        api: {
            create: '/api/applications/getapplicationslist1',
            read: '/api/applications/getapplicationslist',
            update: '/api/applications/getapplicationslist2',
            destroy: '/api/applications/getapplicationslist3'
        }
    }),
    reader: applicationReader,
    autoSave: true,
    autoLoad: true,
    writer: new Ext.data.JsonWriter({
        encode: false,
        listful: false,
        writeAllFields: false
    })
});
那么,是否有人知道问题可能是什么以及如何解决。从我的服务器返回的数据是Json格式的,看起来还可以

{"message":"test","total":2,"applications":[{"ApplicationId":"f82dc920-17e7-45b5-98ab-03416fdf52b2","ApplicationName":"Archivist","UsersCount":6,"RolesCount":3},{"ApplicationId":"054e2e78-e15f-4609-a9b2-81c04aa570c8","ApplicationName":"Test","UsersCount":1,"RolesCount":0}]}

正如我所知,Store'id'配置选项已被删除

据我所知,存储“id”配置选项已被删除

我认为JsonStore在是否进行POST vs PUT操作上与记录id无关。因此,如果id是非用户生成的,它将发出POST,否则将发出PUT。我指的是record.id而不是record.data.id.

我认为JsonStore在是否执行POST vs PUT操作时,会关闭记录id。因此,如果id是非用户生成的,它将发出POST,否则将发出PUT。我指的是record.id而不是record.data.id.

查看Ext.data.Api的源代码,我想说这些动词都搞错了:

重申:{ 创建:“POST”, 读:“得到”, 更新:'PUT', 销毁:“删除” },

对我来说,创建应该是一个PUT,更新应该是一个POST。但我想Sencha的人有不同的想法。 顺便说一句,源代码取自Ext 3.3.1

我想您可以重写restActions对象,使其按预期工作:

Ext.data.Api.restActions = {
create  : 'PUT',
read    : 'GET',
update  : 'POST',
destroy : 'DELETE' };

查看Ext.data.Api的源代码,我会说动词是错误的:

重申:{ 创建:“POST”, 读:“得到”, 更新:'PUT', 销毁:“删除” },

对我来说,创建应该是一个PUT,更新应该是一个POST。但我想Sencha的人有不同的想法。 顺便说一句,源代码取自Ext 3.3.1

我想您可以重写restActions对象,使其按预期工作:

Ext.data.Api.restActions = {
create  : 'PUT',
read    : 'GET',
update  : 'POST',
destroy : 'DELETE' };

我不确定第一部分我的商店用类似的代码打了正确的电话,但我可以解释你问题的第二部分

Ext.data.JsonStore不接受读卡器对象-它只接受字段,并且始终生成自己的读卡器,正如您从源代码中看到的那样

Ext.data.JsonStore = Ext.extend(Ext.data.Store, {
    constructor: function(config){
        Ext.data.JsonStore.superclass.constructor.call(this, Ext.apply(config, {
            reader: new Ext.data.JsonReader(config)
        }));
    }
});
并根据Ext 2.x中的文件确认


因此,如果您提供自己的阅读器,那么在这种情况下,您必须创建一个Ext.data.Store,而不是Ext.data.Store。这也让我感到困惑

不确定第一部分我的存储使用类似的代码进行了正确的调用,但我可以解释您问题的第二部分

Ext.data.JsonStore不接受读卡器对象-它只接受字段,并且始终生成自己的读卡器,正如您从源代码中看到的那样

Ext.data.JsonStore = Ext.extend(Ext.data.Store, {
    constructor: function(config){
        Ext.data.JsonStore.superclass.constructor.call(this, Ext.apply(config, {
            reader: new Ext.data.JsonReader(config)
        }));
    }
});
并根据Ext 2.x中的文件确认


因此,如果您提供自己的读卡器,那么在这种情况下,您必须制作一个Ext.data.Store,而这也让我感到困惑

我也有同样的问题。。我解决了在json存储中建立Success属性并在create方法的响应中返回Success true的问题。。这是我的密码。希望能有帮助

var EStore = new Ext.data.JsonStore
                ({
                   api: { read: 'getAssignedJobs',
                        create: 'createAssignedJobs',
                        update: 'updateAssignedJobs',
                        destroy: 'destroyAssignedJobs'},
                    root: 'jobData',
                    idProperty: 'Id',
                    autoSave: false,
                    autoLoad: true,
                    batch: true,
                    successProperty: 'success',
                    writer: new Ext.data.JsonWriter({ encode: true, writeAllFields: true }),
                    fields: [
                        { name: 'Id', type: 'int', mapping: 'Id' },
                        { name: 'ResourceId', type: 'int', mapping: 'fitter_id' },
                        { name: 'StartDate', type: 'date', dateFormat: "Y-m-d\\TH:i:s" },
                        { name: 'EndDate', type: 'date', dateFormat: "Y-m-d\\TH:i:s" },
                        { name: 'status', type: 'int' },
                        { name: 'job_id', type: 'int' }
                                ]
                });
这是我从服务器端创建的方法

public JsonResult createAssignedJobs(string jobData)
    {
        var Jsondata = (JobfitterToScheduler)new JavaScriptSerializer().Deserialize<JobfitterToScheduler>(jobData);
        JobToFitterRepo jobtofitter = new JobToFitterRepo();
        if (Jsondata != null)
        {
            jobtofitter.insertJobToFitter(13, Jsondata.fitter_id, 0, DateTime.Now, DateTime.Now);
            return this.Json(new { success = true, jobData = Jsondata });
        }
        return null;
    }

我也有同样的问题。。我解决了在json存储中建立Success属性并在create方法的响应中返回Success true的问题。。这是我的密码。希望能有帮助

var EStore = new Ext.data.JsonStore
                ({
                   api: { read: 'getAssignedJobs',
                        create: 'createAssignedJobs',
                        update: 'updateAssignedJobs',
                        destroy: 'destroyAssignedJobs'},
                    root: 'jobData',
                    idProperty: 'Id',
                    autoSave: false,
                    autoLoad: true,
                    batch: true,
                    successProperty: 'success',
                    writer: new Ext.data.JsonWriter({ encode: true, writeAllFields: true }),
                    fields: [
                        { name: 'Id', type: 'int', mapping: 'Id' },
                        { name: 'ResourceId', type: 'int', mapping: 'fitter_id' },
                        { name: 'StartDate', type: 'date', dateFormat: "Y-m-d\\TH:i:s" },
                        { name: 'EndDate', type: 'date', dateFormat: "Y-m-d\\TH:i:s" },
                        { name: 'status', type: 'int' },
                        { name: 'job_id', type: 'int' }
                                ]
                });
这是我从服务器端创建的方法

public JsonResult createAssignedJobs(string jobData)
    {
        var Jsondata = (JobfitterToScheduler)new JavaScriptSerializer().Deserialize<JobfitterToScheduler>(jobData);
        JobToFitterRepo jobtofitter = new JobToFitterRepo();
        if (Jsondata != null)
        {
            jobtofitter.insertJobToFitter(13, Jsondata.fitter_id, 0, DateTime.Now, DateTime.Now);
            return this.Json(new { success = true, jobData = Jsondata });
        }
        return null;
    }

正如我已经说过的那样,“id”选项已不复存在,因此应该使用“storeId”。此外,问题与POST vs PUT无关。商店甚至都不是restful的。正如我已经说过的,“id”选项已经不存在了,所以应该使用“storeId”。此外,问题与POST vs PUT无关。这家商店甚至都不安宁。