如何编辑具有另一个对象作为属性的记录

时间:2012-07-23 16:16:40

标签: extjs

我正在使用ExtJs开发一个应用程序,其中一个功能是编辑已保存的记录。有一个网格,我选择要编辑的行,并出现一个面板,其中包含要编辑的信息。但是可以编辑的属性之一是我的系统的另一个对象,称为配置,并且此配置有一个id,在编辑注册表时会加载该ID。问题是,当我点击允许你编辑的网格图标时,第一次检索到id时,第二次id不再出现,第三次显示以下错误:'

Uncaught TypeError: Cannot read property 'id' of undefined Grid.js:36
Ext.define.columns.items.handler Grid.js:36
Ext.define.processEvent 
Ext.define.processEvent Table.js:755
fire ext-debug.js:8583
Ext.define.continueFireEvent Observable.js:352
Ext.define.fireEvent Observable.js:323
Ext.override.fireEvent EventBus.js:22
Ext.define.processItemEvent Table.js:844
Ext.define.processUIEvent View.js:475
Ext.define.handleEvent View.js:404
(anonymous function)
Ext.apply.createListenerWrap.wrap 

我的代码是(当我点击编辑图标时):

icon : Webapp.icon('editar.png'),
tooltip : 'Editar',
handler: function(view, rowIndex, colIndex, item, e) {                      
var record = Ext.getStore('EstacaoStore').getAt(rowIndex);
var form = Ext.create('PanelNovaEstacao');
record.set('modoIgnorar', record.data.modoIgnorar); 
record.set('latitude', record.data.latitude);   
record.set('longitude', record.data.longitude);
record.set('reiniciar', record.data.reiniciar);             
record.set('configuracaoCombo', record.data.configuracao.id);
record.set('ativar', record.data.ativar);
record.set('tipoColetor', record.data.tipoColetor);
form.loadRecord(record);
Ext.create('Ext.window.Window', {
title : 'Cadastro',
layout : 'fit',
modal : true,
width : 500,
height : 350,
items : [ form ]
}).show();              

'PanelNovaEstacao'代码是:

Ext.define('PanelNovaEstacao', {
extend : 'Ext.form.Panel',
title : 'Painel',
initComponent : function() {

    var combo = Ext.create('ComboBoxConfiguration', {
                name : 'configuracao'
            });

    Ext.apply(this, {
        bodyPadding : '10 0 0 10',
        items : [ {
            xtype : 'hiddenfield',
            name : 'id'
        }, {
            xtype : 'hiddenfield',
            name : 'numeroSerieAntigo'
        }, {
            xtype : 'numberfield',
            fieldLabel : 'Número de série',
            name : 'numeroSerie',
            minValue : 0,
            allowBlank : false
        }, combo
        {
            xtype: 'numberfield',
            fieldLabel: 'Latitude',
            name: 'latitude'
        }, {
            xtype: 'numberfield',
            fieldLabel: 'Longitude',
            name: 'longitude'
        },{
            xtype: 'radiogroup',
            fieldLabel : 'Estado',
            items : [ {
                boxLabel : 'Ativo',
                inputValue : true,
                checked: true,
                name : 'ativar'
            }, {
                boxLabel : 'Inativo',
                inputValue : false,
                name : 'ativar'
            } ]
        }, {
            xtype : 'checkbox',
            fieldLabel : 'Modo ignorar',
            name : 'modoIgnorar'
        }, {
            xtype : 'checkbox',
            fieldLabel : 'Reiniciar',
            name : 'reiniciar'
        }, {
            xtype : 'button',
            text : 'Salvar',
            textAlign : 'center',
            action : 'salvar'
        } ]
    });

    this.callParent(arguments);
}

});

ComBoxConfiguration代码:

Ext.define('ComboBoxConfiguration', {
extend : 'Ext.form.ComboBox',
store : 'ConfiguracaoStore',
fieldLabel : 'Configurações',
displayField : 'id'

});

任何人都知道可能会发生什么? 谢谢!

2 个答案:

答案 0 :(得分:0)

此行可能会导致此问题:record.set('configuracaoCombo', record.data.configuracao.id);

从代理返回的数据没有configuracao属性,因此访问它的计算结果为undefined,此时尝试访问子属性id将导致你看到的错误。

查看EstacaoStore中的数据以及商店代理返回的内容(或者加载它)。你可能会在那里发现问题。

答案 1 :(得分:0)

当我点击并运行代码时: var record = Ext.getStore('EstacaoStore')。getAt(rowIndex); 的console.log(记录); 返回的对象是:(configuracao是configuracaoEstacao的同义词)

enter image description here