ExtJS传递store.sync()上的所有字段



在 ExtJS 6.5.0 中,我创建了一个商店和一个可编辑的网格面板:

Ext.define('StateStore',{
extend: 'Ext.data.Store',
alias: 'store.stateStore',
storeId  : 'StateStore',
fields: ['Id', 'Name', 'SortIndex'],
autoLoad : true,
proxy: {
type : 'ajax',
api  : {
create  : undefined,
read    : '/kanban/states/read/' + kanbanId,
update  : '/kanban/states/update/' + kanbanId,
destroy : undefined
},
writer : {
type        : 'json',
allowSingle : false
}
}
});

var StateList = Ext.create({
xtype : 'gridpanel',
selModel: 'cellmodel',
title : 'Manage States',
store : {
type: 'stateStore'
},
plugins: {
ptype: 'cellediting',
clicksToEdit: 1
},
columns: [
{
text: 'ID',
dataIndex: 'Id',
flex: 1
},{
text: 'Name',
dataIndex: 'Name',
flex: 2, 
editor: {
field: {
type: 'textfield',
allowBlank: false
}
}
},
{ 
text: 'SortIndex',
dataIndex: 'SortIndex',
flex: 1,
}
],
});

当用户完成编辑并单击保存时,将调用 store.sync(( 函数,但它只会将修改后的记录和字段传递给服务器。我使用record.dirty=true强制它通过所有记录,但未修改的字段仍未通过。

为什么要传递所有记录和字段?因为我想删除现有记录并在每次更新时创建新记录。所以我不需要单独处理创建/更新/删除。只有几个条目,因此性能不是问题。

一种解决方案是使用Ext.Ajax()而不是sync(),我想知道有没有更好的解决方案?

使用writeAllFields: true配置编写器。

相关文档。

最新更新