ExtJS将值分配给隐藏字段

时间:2018-10-02 20:13:26

标签: extjs

我将下面的组合框设置为通过API调用放置一些记录,然后显示在页面上。用户单击提交时,我需要提交2个值,1)gmiExchangeCode和2)gmiFuturesCode。第一个值在此表单的字段中起作用,gmiFuturesCode在更新隐藏的表单字段中不起作用。

}, {
            xtype: 'combo',
            autoLoad: true,
            hideTrigger: true,
            fieldLabel: 'Product',
            displayField: 'gmiDescription',
            valueField: 'gmiExchangeCode',
            submitValue: true,
            name: 'exchange',
            queryMode: 'remote',
            queryParam: 'entry',
            typeAhead: true,
            minChar: 2,
            tpl: new Ext.XTemplate('<tpl for="."><div class="x-boundlist-item" style="border-bottom:1px solid #757575;">{gmiExchangeCode} - {lisaMarket} - {gmiFuturesCode} - {gmiDescription}</div></tpl>'),
            store: {
                fields: ['text', 'value'],
                proxy: {
                    type: 'ajax',
                    url: 'API',
                    reader: {
                        type: 'json'
                    }
                }
            },
            listeners: {
                select: function (combo, record, index) {
                    hidden.setValue(record.get('gmiFuturesCode'));
                }
            }
        }, {
            xtype: 'hidden',
            id: 'futures',
            name: 'futures'
        }, {

2 个答案:

答案 0 :(得分:0)

没有什么叫“ hidden.setValue()”的东西,您必须使用查询选择器或Ext.getCmp('ObjectID')来获取对象

这是一个有效的示例Fiddle

Ext.create('Ext.form.Panel', {
title: 'test',
width: 400,
height: 300,
renderTo: Ext.getBody(),
items: [{
    xtype: 'combobox',
    reference: 'states',
    publishes: 'value',
    fieldLabel: 'Select State',
    displayField: 'displayField',
    anchor: '-15',
    store: {
        fields: ['valueField', 'displayField'],
        data: [
            ['1', 'MyDisplayValueFor1'],
            ['2', 'MyDisplayValueFor2'],
            ['3', 'MyDisplayValueFor3']
        ]
    },
    minChars: 0,
    queryMode: 'local',
    typeAhead: true,
    listeners: {
        select: function (combo, record, index) {
            console.log(record.get('displayField'));
            Ext.getCmp('futures').setValue(record.get('displayField'));
            Ext.Msg.alert('Alert', 'The hidden Field value from the getter is : ' + Ext.getCmp('futures').getValue());
        }
    }
}, {
    xtype: 'hidden',
    id: 'futures',
    name: 'futures'
}]

})

答案 1 :(得分:0)

尝试一下

Ext.getCmp('futures').setValue(record.get('gmiFuturesCode'));