2010-06-09 44 views
1

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

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没有读者它的工作原理,但是当我尝试更新任何领域它使用的不是“更新”我的“创造”的网址。

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 
    }) 
}); 

我认为问题是我不使用阅读器,但是当我使用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}]} 

回答

0

正如我设法知道商店的'ID'配置选项被depricated。

0

我认为JsonStore在关于是否执行POST与PUT的时候关闭了记录ID。因此,如果该ID是非用户生成的,它将发出POST,否则将发出PUT。我指的是record.id not record.data.id。

+0

正如我已经告诉了“身份证”选项也没有了,所以应该使用“STOREID”,而不是。 此外,问题与“POST VS PUT”没有任何关系。这家商店甚至不宁静。 – kalan 2010-06-10 06:31:09

1

纵观源Ext.data.Api我要说的是,动词是搞砸了:

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

对我来说,创造应该是一个PUT和更新应该是一个POST。但我猜Sencha的人有不同的想法。 顺便说一句,源是从内线取3.3.1

我想你可以覆盖restActions反对作品如你所愿:

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

不知道的第一部分(我的店做出正确的电话与类似的代码),但我可以阐明你的问题的第二部分。

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) 
     })); 
    } 
}); 

看到和被确认为“为每在分机2.x的文档”

http://www.sencha.com/forum/showthread.php?57189-2.x-Closed-Bug-in-Ext.data.JsonStore-cconstructor

所以,如果你提供自己的读者,你必须在这种情况下,做出Ext.data.Store,而不是(这抓住了我出过)

5

我有同样的问题..我解决了它在json商店中建立Success Property,并在创建方法的响应中返回成功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; 
    }