Extjs PUT url ID错误

时间:2014-02-02 11:41:15

标签: rest url extjs model

我是senach和ExtJs的新手,我正在尝试读写json数据。获取数据已经有效,但我无法将更改的数据写回服务器。

我正在使用 ExtJs 4.2

我在RestProxy网址中配置了一个网址:/animals/dogs/

获取http://example.com/animals/dogs

PUT http://example.com/animals/dogs/{id}

Get正在按预期工作。但是PUT URL是:

example.com/animals/dogs/project.model.dogs-3?dc435453...

id还包含模型名称。如何将此更改为上面的ID?

这是商店:

Ext.define('project.store.MyJsonStore', {


 extend: 'Ext.data.Store',

    requires: [
        'project.model.dogs',
        'Ext.data.proxy.Rest',
        'Ext.data.reader.Json'
    ],

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            autoLoad: true,
            autoSync: true,
            model: 'project.model.dogs',
            storeId: 'MyJsonStore',
            proxy: {
                type: 'rest',
                limitParam: 'count',
                url: '/animals/dogs,
                reader: {
                    type: 'json',
                    idProperty: 'id',
                    root: 'data'
                }
            }
        }, cfg)]);
    }
});

这是模型:

Ext.define('project.model.dogs', {
    extend: 'Ext.data.Model',

    requires: [
        'Ext.data.Field'
    ],

    clientIdProperty: 'id',

    fields: [
        {
            name: 'id',
            type: 'int'
        },
        {
            name: 'type',
            type: 'string'
        }
    ]
});

GET响应:(读者根是数据)

{
  "success": true,
  "data": 
  [
    {
      "id": 1,
      "type": "Some Type",     
      "url": "/animals/dogs/1"
    },
    {
      "id": 2,
      "type": "Some other Type",     
      "url": "/animals/dogs/2"
    },  

  ]
}

PUT网址看起来像:

example.com/animals/dogs/project.model.dogs-3?dc...
example.com/animals/dogs/project.model.dogs-7?dc...
example.com/animals/dogs/project.model.dogs-8?dc...

数字3,7,8是id,因此extjs识别模型中的id属性。

此致 Sencha初学者

0 个答案:

没有答案