首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JsonStore和JsonReader的问题

JsonStore和JsonReader的问题
EN

Stack Overflow用户
提问于 2010-06-09 16:49:14
回答 5查看 6.6K关注 0票数 1

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

代码语言:javascript
复制
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}]
    });

当我在没有阅读器的情况下使用JsonStore时,它可以工作,但当我试图更新任何字段时,它会使用我的“创建”url而不是“更新”。

代码语言:javascript
复制
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
    })
});

我认为问题在于我没有使用reader,但当我使用JsonReader时,网格将完全停止显示任何数据。

代码语言:javascript
复制
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格式的,并且没有问题。

代码语言:javascript
复制
{"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}]}
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2010-06-09 19:57:02

据我所知,Store 'id‘配置选项被取消了。

票数 0
EN

Stack Overflow用户

发布于 2011-08-03 17:28:40

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

代码语言:javascript
复制
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' }
                                ]
                });

这是我在服务器端的Create方法。

代码语言:javascript
复制
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;
    }
票数 5
EN

Stack Overflow用户

发布于 2010-12-15 03:08:31

看一下Ext.data.Api的源代码,我会说动词搞砸了:

restActions : { create : 'POST', read : 'GET', update : 'PUT', destroy : 'DELETE' },

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

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

代码语言:javascript
复制
Ext.data.Api.restActions = {
create  : 'PUT',
read    : 'GET',
update  : 'POST',
destroy : 'DELETE' };
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3004286

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档