JsonStore和JsonReader的问题

kal*_*lan 1 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 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}]
    });
Run Code Online (Sandbox Code Playgroud)

当我使用没有阅读器的JsonStore时它可以工作,但当我尝试更新任何字段时,它使用我的'create'url而不是'update'.

var applicationsStore = new Ext.data.JsonStore({
    root: 'applications',
    totalProperty: 'total',
    idProperty: 'ApplicationId',
    messageProperty: 'message',
    fields: [{ name: 'ApplicationId' }, { name: 'ApplicationName', allowBlank: false }, { name: 'UsersCount', allowBlank: false }, { name: 'RolesCount', allowBlank: false}],
    id: 'app1234',
    proxy: new Ext.data.HttpProxy({
        api: {
            create: '/api/applications/getapplicationslist1',
            read: '/api/applications/getapplicationslist',
            update: '/api/applications/getapplicationslist2',
            destroy: '/api/applications/getapplicationslist3'
        }
    }),        
    autoSave: true,
    autoLoad: true,
    writer: new Ext.data.JsonWriter({
        encode: false,
        listful: false,
        writeAllFields: false
    })
});
Run Code Online (Sandbox Code Playgroud)

我认为问题在于我不使用阅读器,但是当我使用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
    })
});
Run Code Online (Sandbox Code Playgroud)

那么,有谁知道问题可能是什么以及如何解决它.从我的服务器返回的数据是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}]}
Run Code Online (Sandbox Code Playgroud)

小智 5

我有同样的问题..我解决了它在json商店中建立Success Property并在我的create方法的响应中返回成功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' }
                                ]
                });
Run Code Online (Sandbox Code Playgroud)

这是我从服务器端创建的方法..

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;
    }
Run Code Online (Sandbox Code Playgroud)