EXTJS模型idProperty字段是否填充了型号名称?

Rhu*_*b65 9 rest extjs5

我正在尝试针对Restful RubyonRails后端创建一个简单的ExtJS5应用程序.出于某种原因,当我实例化模型时,ExtJs使用模型(和计数器)的名称填充"idProperty"字段.例如

{ "Traffic_id": "MyApp.model.Person-1", "EXTERNAL_ID":0,...

我认为"idProperty"字段本质上是数据记录的主键,通常在将记录插入数据库时​​自动设置(自动增量)

因此,此字段应为null或类似,因为模型尚未添加到商店并同步到后端.

更令人惊讶的是,该字段定义为'int',ExtJS将字符串放入其中!

有人能告诉我发生了什么事吗?

彼得

下面是一个小提琴的app.js:

Ext.application({
    name : 'Fiddle',

    launch : function() {

        var model = Ext.create('MyApp.model.Person');

       Ext.Msg.alert('Fiddle', JSON.stringify(model.data));

    }
});

Ext.define('MyApp.model.Person', {
    extend: 'Ext.data.Model',
    idProperty: 'Traffic_id',

    proxy: {
        type: 'rest',
        // url: '/traffics.json',
        format: 'json',
        api: {
            create: 'traffics',
            read: 'traffics',
            update: 'traffics/edit',
            destroy: 'traffics'
        },

        reader: {
            type: 'json',
            rootProperty: 'traffic',
            successProperty: 'success',
            messageProperty: 'message'
        },
        writer: {
            type: 'json',
            //writeAllFields  : false,
            //encode: true,
            rootProperty: 'traffic'
        },
        afterRequest: function(req, res) {
            console.log("Ahoy!", req.operation.response);
        },
        listeners: {
            exception: function(proxy, response, operation) {
                //debugger;
                Ext.MessageBox.show({
                    title: 'XXX REMOTE EXCEPTION',
                    msg: operation.getError(),
                    icon: Ext.MessageBox.ERROR,
                    buttons: Ext.Msg.OK
                });
            }
        }
    },

    fields: [{
        name: 'Traffic_id',
        type: 'int'
    }, {
        name: 'external_id',
        type: 'int'
    }, {
        name: 'description',
        type: 'string'
    }, {
        name: 'insertUser',
        type: 'string'
    }, {
        name: 'insertDate',
        type: 'date'
    }]

});
Run Code Online (Sandbox Code Playgroud)

Rob*_*ins 0

ExtJS 为新创建的模型分配一个“临时”id;它可以区分已在客户端创建但尚未保存的模型(“幻影”​​模型)与已下载的模型。因此,它知道何时调用createvs update,并且它会(我认为,从内存中)在上传到 REST 端点时删除 ID create

它需要 ID,因为新创建的模型可以进入商店(例如,用于会话,如果没有其他的话)。

您看到的 ID 样式来自默认sequential生成器。

有关更多信息,请参阅http://docs.sencha.com/extjs/5.0/apidocs/#!/api/Ext.data.identifier.Generator