Extjs store.save() 无法识别更新

发布于 2024-12-06 12:30:03 字数 3001 浏览 3 评论 0原文

我按照 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紧拥背影 2024-12-13 12:30:03

我在 JSONWriter 中进行了更改

idProperty : 'finCol0' to idProperty : 'fundHeadSeq'

 {name: 'finCol0',mapping:'fundHeadSeq'}, to {name: 'fundHeadSeq',mapping:'fundHeadSeq'},

{header: 'id', dataIndex: 'finCol0', align: 'left', hidden: true, hideable: false, sortable: false, width: 70},
to
{header: 'id', dataIndex: 'fundHeadSeq', align: 'left', hidden: true, hideable: false, sortable: false, width: 70},

在列模型中进行了更改,一切都按预期工作。

I have change

idProperty : 'finCol0' to idProperty : 'fundHeadSeq'

and

 {name: 'finCol0',mapping:'fundHeadSeq'}, to {name: 'fundHeadSeq',mapping:'fundHeadSeq'},

in JSONWriter and change

{header: 'id', dataIndex: 'finCol0', align: 'left', hidden: true, hideable: false, sortable: false, width: 70},
to
{header: 'id', dataIndex: 'fundHeadSeq', align: 'left', hidden: true, hideable: false, sortable: false, width: 70},

in column model and everything work as expected.

心安伴我暖 2024-12-13 12:30:03

我有一个和你类似的问题。

我的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文