【问题标题】:Extjs 4 updateRecord errorExtjs 4 更新记录错误
【发布时间】:2012-01-19 18:53:29
【问题描述】:

(如果帖子太长,请先抱歉,我只是添加了所有涉及问题的代码,然后我认为可能会更容易得到答案)

您好,我尝试在 extjs 4 中更新商店时遇到问题。

作为备份,我正在开发一个通用网格,您可以在其中发送您需要的列以及窗口中的字段以向网格添加新行,这就是 通用网格强>:

Ext.define('masterDataGridControls', {
        extend : 'Ext.grid.Panel',

        id : 'panelWin',
        windowItems : null,
        addWin : null,

        initComponent : function() {
            var me = this;

            Ext.applyIf(me, {
                        dockedItems : [{
                            xtype : 'toolbar',
                            dock : 'top',
                            items : [{
                                        xtype : 'button',
                                        id : 'btn_delete',
                                        iconCls : 'deleteIcon',
                                        tooltip : 'Delete row or group',
                                        handler : function() {
                                            var selection = me.getView()
                                                    .getSelectionModel()
                                                    .getSelection()[0];
                                            if (selection) {
                                                store.remove(selection);
                                            }
                                        }
                                    }, {
                                        xtype : 'button',
                                        id : 'btn_add',
                                        iconCls : 'addIcon',
                                        tooltip : 'Add row or group',
                                        handler : me.addToList
                                    }]
                        }]
                    });

            me.callParent(arguments);
        },

        getAddWindow : function() {
            if (!this.addWin) {
                this.addWin = new windowPop({
                            formItems : this.windowItems,
                            idParent : this.config.id,
                            record : this.store.model.prototype
                        });
            }
            return this.addWin;
        },

        addToList : function() {
            var addWindow = this.findParentByType().findParentByType()
                    .getAddWindow();;
            addWindow.show();
        }
    });

我有一个类 windowPop,它接收字段、显示它们并保存数据:

Ext.define("windowPop", {
extend : "Ext.window.Window",
formPanel : null,
formItems : null,
record : null,
idParent : null,

initComponent : function() {
    var me = this;

    me.formPanel = new Ext.form.Panel({
                items : this.formItems,
                layout: 'anchor'
            });

    Ext.applyIf(me, {
                resizable : false,
                closable : false,
                width : 300,
                minWidth : 300,
                minHeight : 200,
                y : 150,
                layout : 'fit',
                plain : true,
                modal : true,
                items : [me.formPanel],
                buttons : [{
                            text : "i_Save",
                            handler : function() {
                                console.info(me.record);
                                me.formPanel.getForm().updateRecord(me.record);
                                Ext.getCmp(me.idParent).fireEvent("winSave",me.record);
                                me.formPanel.getForm().reset();
                                me.hide();
                            }
                        }, {
                            text : 'i_Cancel',
                            handler : function() {
                             me.formPanel.getForm().reset();
                                me.hide();
                            }
                        }]
            });
    me.callParent(arguments);
}
});

我有我的特定网格,我在其中定义了一个 data.model,现在我使用的是固定存储,但稍后将被我从服务器获取的存储替换:

Ext.define('userKeys', {
        extend : 'Ext.data.Model',
        fields : [{
                    name : 'text',
                    type : 'string'
                }, {
                    name : 'description',
                    type : 'string'
                }, {
                    name : 'group',
                    type : 'string'
                }]
    });

var store = Ext.create('Ext.data.Store', {
        model: 'userKeys',
        data : [{
                    text : "que mamera",
                    description : "asdfasdf",
                    group : 'homework'
                }, {
                    text : "book report",
                    description : 'hola',
                    group : 'homework'
                }, {
                    text : "alegebra",
                    description : "haha",
                    group : 'homework'
                }, {
                    text : "buy lottery tickets",
                    description : "kajsdf",
                    group : 'homework'
                }]

    });


Ext.define('ConfigInterfacesUserKeys', {
        extend : 'masterDataGridControls',

        initComponent : function() {
            var me = this;

            me.columns = [{
                        id : 'cl_input',
                        header : 'i_Text',
                        dataIndex : 'text',
                        width : 220
                    }, {
                        header : 'i_Description',
                        dataIndex : 'description',
                        width : 130
                    }, {
                        header : 'i_group',
                        dataIndex : 'group',
                        width : 130
                    }];

            me.windowItems = [{
                        xtype : 'textfield',
                        id : 'txt_sendTime',
                        fieldLabel : 'text',
                        margin : '5 0 0 5',
                        style : 'font-weight:bold',
                        labelWidth : 120,
                        name : 'text'
                    }, {
                        xtype : 'textfield',
                        id : 'txt_waitTime',
                        fieldLabel : 'description',
                        margin : '5 0 0 5',
                        style : 'font-weight:bold',
                        labelWidth : 120,
                        name : 'description'
                    }, {
                        xtype : 'textfield',
                        id : 'txt_group',
                        fieldLabel : 'group',
                        margin : '5 0 0 5',
                        style : 'font-weight:bold',
                        labelWidth : 120,
                        name : 'group'
                    }];

            me.store = store;

            me.callParent(arguments);
        }
    })

问题

当我尝试保存您在 windowPop 类中看到的字段时,我正在这样做:

me.formPanel.getForm().updateRecord(me.record);

但我得到下一个错误:

this[this.persistenceProperty] is undefined

我追查了错误,发现所有在函数 updateRecord 尝试将对象设置为存储时开始:

updateRecord: function(record) {
    var fields = record.fields,
    values = this.getFieldValues(),
    name,
    obj = {};
    fields.each(function(f) {
        name = f.name;
        if (name in values) {
            obj[name] = values[name];
        }
    });
    record.beginEdit();
    **record.set(obj);**
    record.endEdit();
    return this;
} 

我从通用网格发送模型窗口不知道是不是有问题,我发送了这样:

record : this.store.model.prototype

然后我不确定是不是因为我发送的模型不太好。

我一直在网上搜索,但找不到正确的答案,如果您能以正确的方式指导我,这将非常有帮助。

谢谢

【问题讨论】:

    标签: extjs extjs4 store


    【解决方案1】:

    不知道是不是我把模型发到 来自一般网格的窗口

    我相信是的。您发送的不是空实例(应该发送),而是一个类的原型。尝试发送:

    record : new this.store.model()
    

    【讨论】:

    • 它工作了:),然后问题是因为我正在发送一个已经填充的对象,我应该发送模型但是空的......非常感谢:)......
    猜你喜欢
    • 2011-09-07
    • 1970-01-01
    • 2014-01-21
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    相关资源
    最近更新 更多