extjs组合框函数getvalue()返回包含多个字段值的对象

问题描述 投票:0回答:1

组合框 getValue() 是否可以返回对象?

我的组合框存储字段包含 ID、代码、描述 1、描述 2

我希望返回 ID、描述 1。描述2.

extjs
1个回答
0
投票

您可能想使用

combobox.getValue()
,而不是使用
combobox.getSelection().getData()

选择模型返回完整记录。

如果必须使用 getValue(),则必须创建一个自定义组合框。 请记住,这在很多地方都可以直接使用,例如

form.getValues()
。意思是:这需要更多测试!!!

/**
 * @return {Object|''}
 */
Ext.define('ValueCombobox', {
    extend: 'Ext.field.ComboBox',
    xtype : 'valuecombobox',

    getValue: function (combobox, a, b) {
        const value = this.callParent(),
              hasValue = !Ext.isEmpty(value),
              hasRecord = hasValue && this.getSelection();
              
        return hasRecord && hasRecord.getData() || '';
    }
});
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.