具有同步功能的rowedit网格 [英] rowedit grid with sync
问题描述
我尝试实现一个通用的行编辑网格,例如此例子,不同之处在于我想将更改与服务器后端同步.到目前为止,我可以使用onRoweditAdd
添加新行.
I try to implement a general rowediting grid like this example, with the difference that I would like to sync the changes with the server backend. Until now, I can add a new line with onRoweditAdd
.
Ext.define('Mb.view.base.RoweditListController', {
extend: 'Ext.app.ViewController',
alias: 'controller.roweditlist',
onRoweditAdd: function(me){
var grid = me.up('panel'),
edit = grid.editingPlugin,
store = grid.getStore(),
record = store.getModel().create({id: 0});
edit.cancelEdit()
store.insert(0, record)
edit.startEdit(record, 0)
},
editRowedit: function(editor, ctx) {
var store = ctx.grid.getStore();
store.sync()
}
})
问题是store.sync()
不会将create
请求发送到服务器,而是发送update
请求.似乎没有考虑store.insert(0, record)
.仅同步用户所做的修改.罪魁祸首是什么?
The problem is that store.sync()
does not send a create
request to the server, but an update
request. It looks like store.insert(0, record)
is not accounted for. Only the modification done by the user is synched. What could be the culprit ?
推荐答案
通过在记录中提供现有的id
,ExtJS假定此记录已存在于您的商店中并且必须进行更新.如果您不提供ID,则它假定它是新创建的记录,并且将遵循创建路线.这是基于这样的假设:您使用生成的ID策略(通常应该这样做),因此您永远不会在创建时自己提供ID.
By giving an existing id
in a record, ExtJS assumes this record already exist in your store and has to be updated. If you don't give an id then it supposes it is a newly created record and will go the create route. This comes from the assumption that you use a generated ID strategy (which you generally should) and thus you would never provide IDs yourself upon creation.
在后台,ExtJS将记录标记为幻像:true或false.虚拟记录是仅存在于前端且尚未持久的记录.创建没有id
的记录会将其标记为幻像,而创建具有已提供的ID的记录不会将其标记为幻像,也不会触发创建调用,而是会触发更新
Under the hood, ExtJS marks the record as phantom: true or false. Phantom records are the ones that only exist in the front end and haven't been persisted yet. Creating a record with no id
will mark it as phantom whereas creating a record with an id already provided will not mark it as phantom and will not trigger a create call but an update instead
这篇关于具有同步功能的rowedit网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!