在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()
,我想知道有更好的解决方案吗?