0
在ExtJS的6.5.0,我创建了一个存储和编辑的GridPanel:ExtJS的传递store.sync所有字段()
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会执行。这在以前的版本中默认设置为true,但对于6.5.0,您必须手动进行设置。 – Shahbaz
'true'将记录中的所有字段写入服务器。如果设置为false,它只会发送已修改的字段。这只适用于'record'内的'fields'。它不会将所有记录发送到服务器。 –
@Shahbaz不知道你做了什么,但是自从我开始使用ExtJS回到v4.2.1以来,我不得不手动进行设置。 – Alexander