0

我正在使用 ExtJs 开发应用程序,其中一个功能是编辑已保存的记录。有一个网格,我可以在其中选择要编辑的行,然后会出现一个面板,其中包含要编辑的信息。但是其中一个可以编辑的属性是我系统的另一个对象,叫做一个配置,这个配置有一个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);
}

});

ComBox配置代码:

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

});

有谁知道可能会发生什么??谢谢!

4

2 回答 2

0

This line is likely causing the issue: record.set('configuracaoCombo', record.data.configuracao.id);

The data that is coming back from the proxy does not have a configuracao property, so accessing it evaluates to undefined, at which point trying to access the sub-property id will lead to the error you are seeing.

Take a look at the data in the EstacaoStore and what's being returned by the store's proxy (or however you load it). You'll likely find a problem there.

于 2012-07-23T16:32:13.353 回答
0

When I click in line and run the code: var record = Ext.getStore('EstacaoStore').getAt(rowIndex); console.log(record); The object that return is: (configuracao is synonymous to configuracaoEstacao)

enter image description here

于 2012-07-23T18:09:15.873 回答