新记录获得自动生成的id值。如何在ExtJs 4中获得0作为新ID?

时间:2017-02-15 17:48:43

标签: extjs extjs4 upgrade extjs6 extjs-stores

在ExtJs 4中,商店中的新记录在同步到服务器之前获得了0作为id。在ExtJs 6中,标识为'Mb.model.images.Image-1'

Ext.define('Mb.model.images.Image', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id', type: 'int'},
        {name: 'code', type: 'string'},
        {name: 'filename', type: 'string'},
        {name: 'path', type: 'string'}
    ]
})

是否有可能在ExtJs 6中获得旧行为?

我查看了identifier: 'sequential',但这会在客户端分配一个自动增量ID,它将与服务器端分配的ID冲突。

1 个答案:

答案 0 :(得分:2)

不,不是。会话周围 ExtJS 5 的变化要求所有模型都具有唯一的ID

您可以使用phantom属性查看模型是否从未保存过。

此外,Proxy类知道模型是否是幻像,并将根据幻像标志的状态(Create operations vs Update operations)发出不同的调用。

任何服务器端分配的ID都会覆盖刚刚保存的模型的ID