【问题标题】:How do i submit the fieldValue of a combobox in Extjs 4?如何在 Extjs 4 中提交组合框的 fieldValue?
【发布时间】:2012-01-26 23:35:57
【问题描述】:

我正在使用 Extjs 4.0.7 并且很难在 formPanelsubmit 中获得 combobox fieldValue combobox 上所选选项的fieldValue

据我所知,这通常是通过将hiddenName 配置选项设置为您希望它提交的值来实现的;就像在 html 中使用隐藏字段一样,但 hiddenName 选项现在似乎已从文档中删除,没有任何明显的替代方案。

那么我该如何继续提交我的formPanel 与Extjs 4 中valueField 的值?

这是我的应用程序的一个片段,我在其中定义了一个组合框:

xtype: 'combobox',
        name: 'shift',
        hiddenName: 'shiftid',
        id: 'shiftCombobox',
        fieldLabel: 'Shift',
        labelWidth: 30,
        width: 130,
        margin: '0 5',
        cls: 'shift',
        store: shiftStore, 
        autoSelect: true,
        queryMode: 'local',
        displayField: 'name',
        valueField: 'objectid',
        autoSelect: true,
        handler: function() {
            //changeShift(); 
        }

这是shiftStore使用的模型:

Ext.define('shiftModel', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'objectid', type: 'int'},
        {name: 'name', type: 'string'}
    ]
});

【问题讨论】:

  • 我找到了解决方案,但还不能回答我自己的问题。随意发布一个可靠的方法来控制提交的内容

标签: extjs extjs4


【解决方案1】:

我忘记了这段代码:

autoLoad: {
        //The callback here is needed to fix a bug and set a default value in the combobox. 
        scope: this,
        callback: function() {
            var comboBox = Ext.getCmp("teamCombobox");
            var store = comboBox.store;

            // set the value of the comboBox here
            comboBox.setValue(store.getAt('0').get('name'));
        }
    }

这会更新combobox 的商店autoLoad 上的combobox,以在加载时使用默认值。 我已将值设置为 name,即displayValue。将值设置为对应的fieldValue,在我的例子中是一个名为objectid

的字段

我这样设置后,它就可以工作了:

comboBox.setValue(store.getAt('0').get('objectid'));

现在combox 提交的是真实的fieldValue,而不是我不小心设置的文本值。

我仍然想知道是否有某种方法可以控制这种情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 2011-11-13
    • 1970-01-01
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多