Extjs store.save() 无法识别更新
我按照 writer 中的说明创建网格具有 CRUD 能力,但问题是当我编辑现有行并 save() 时,它会识别出创建的脏行,我认为问题可能出在我的 idProperty 中,如 链接,但不知道如何操作。
这是我的代码
列模型
var xsmWin = new Ext.grid.CheckboxSelectionModel({checkOnly:true});
var xcmWin = new Ext.grid.ColumnModel([
xsmWin,
new Ext.grid.RowNumberer(),
{header: 'id', dataIndex: 'finCol0', align: 'left', hidden: true, hideable: false, sortable: false, width: 70},
{header: 'column name', dataIndex: 'finCol2', align: 'left', hidden: false, hideable: false, sortable: true, width: 100, editor: new samart.form.xTextField({allowBlank: false})},
{header: 'input type', dataIndex: 'finCol3', align: 'left', hidden: false, hideable: false, sortable: true, width: 100},
{header: 'approve', dataIndex: 'approveFlag', align: 'center', hidden: false, hideable: false, sortable: true, width: 50},
]);
代理
var proxyWin = new Ext.data.HttpProxy({
api : {
read : {
url : SERVLET_URL + '&action=loadInnerDataGrid',
method: 'POST'
},
create : {
url : SERVLET_URL + '&action=createInnerData',
method: 'POST'
},
update : {
url : SERVLET_URL + '&action=updateInnerData',
method: 'POST'
},
destroy : {
url : SERVLET_URL + '&action=destroyInnerData',
method: 'POST'
}
}
});
读取器和写入器
var writerWin = new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
});
var readerWin = new Ext.data.JsonReader(
{
idProperty: 'finCol0',
root: 'data'
},[
{name: 'finCol0',mapping:'fundHeadSeq'},
//{name: 'finCol1',mapping:'fundType'},
{name: 'finCol2',mapping:'headLabel'},
{name: 'finCol3',mapping:'objectName'},
{name: 'approveFlag',convert: function(v, record){
if (record.approveFlag == 'Y') {
return 'Yes';
} else if (record.approveFlag == 'N') {
return 'No';
}
}},
]
)
存储
var xstoreWin = new Ext.ux.data.PagingStore({
storeId : 'xstoreWin',
proxy : proxyWin,
reader : readerWin,
writer : writerWin,
autoSave : false,
autoLoad : true
});
I follow instruction in writer to create grid with CRUD ability, but the problem is when I edit existing row and save() it recognize that dirty row as create, I think the problem may lie in my idProperty as in link, but can't figure out how.
Here is my code
Column model
var xsmWin = new Ext.grid.CheckboxSelectionModel({checkOnly:true});
var xcmWin = new Ext.grid.ColumnModel([
xsmWin,
new Ext.grid.RowNumberer(),
{header: 'id', dataIndex: 'finCol0', align: 'left', hidden: true, hideable: false, sortable: false, width: 70},
{header: 'column name', dataIndex: 'finCol2', align: 'left', hidden: false, hideable: false, sortable: true, width: 100, editor: new samart.form.xTextField({allowBlank: false})},
{header: 'input type', dataIndex: 'finCol3', align: 'left', hidden: false, hideable: false, sortable: true, width: 100},
{header: 'approve', dataIndex: 'approveFlag', align: 'center', hidden: false, hideable: false, sortable: true, width: 50},
]);
Proxy
var proxyWin = new Ext.data.HttpProxy({
api : {
read : {
url : SERVLET_URL + '&action=loadInnerDataGrid',
method: 'POST'
},
create : {
url : SERVLET_URL + '&action=createInnerData',
method: 'POST'
},
update : {
url : SERVLET_URL + '&action=updateInnerData',
method: 'POST'
},
destroy : {
url : SERVLET_URL + '&action=destroyInnerData',
method: 'POST'
}
}
});
Reader and Writer
var writerWin = new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
});
var readerWin = new Ext.data.JsonReader(
{
idProperty: 'finCol0',
root: 'data'
},[
{name: 'finCol0',mapping:'fundHeadSeq'},
//{name: 'finCol1',mapping:'fundType'},
{name: 'finCol2',mapping:'headLabel'},
{name: 'finCol3',mapping:'objectName'},
{name: 'approveFlag',convert: function(v, record){
if (record.approveFlag == 'Y') {
return 'Yes';
} else if (record.approveFlag == 'N') {
return 'No';
}
}},
]
)
Store
var xstoreWin = new Ext.ux.data.PagingStore({
storeId : 'xstoreWin',
proxy : proxyWin,
reader : readerWin,
writer : writerWin,
autoSave : false,
autoLoad : true
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 JSONWriter 中进行了更改
,
并
在列模型中进行了更改,一切都按预期工作。
I have change
and
in JSONWriter and change
in column model and everything work as expected.
我有一个和你类似的问题。
我的
IdProperty
是'user_id'
并且 writer create 从未被调用。我更改为'userId'
现在可以使用了。很奇怪。我使用的是
Extjs 3.4
。I have a problem similar to yours.
My
IdProperty
was'user_id'
and the writer create was never called. I changed to'userId'
and it work now.Very strange. I'm under
Extjs 3.4
.