简体   繁体   English

Extjs5:组合框未显示所选值

[英]Extjs5 : ComboBox not showing the selected value

I created a comboBox and when I select a value, no value will be displayed. 我创建了一个comboBox ,当我选择一个值时,将不会显示任何值。

 Ext.create("Ext.form.field.ComboBox", {
        name: el.name,
        fieldLabel: el.labelId,
        hidden: !(el.visible),
        displayField:"value",
        valueField:"value",
        flex: 1,
        store:Ext.create("Ext.data.Store",{
               fields: ['key', 'value'],
               data: [
                        { key: "10",value: "etap 0"},
                        { key: "200",value: "etape 1"},
                        { key: "300", value: "etape 3"}
               ]
        }),
        regex: el.parameterType.regex,
        regexText: el.regExErrMsg,
        allowBlank: !el.mandatory,
        blankText: el.requiredErrMsg
    })

EDIT 编辑

Here is exactly the method that return combo: 这正是返回combo的方法:

 drawField: function (el) {
    var me = this;
    var uiField = Ext.create(me.componentType, {
        name: el.name,
        fieldLabel: el.labelId,
        hidden: !(el.visible),
        flex: 1,
        regex: el.parameterType.regex,
        regexText: el.regExErrMsg,
        allowBlank: !el.mandatory,
        blankText: el.requiredErrMsg
    });
    if (el.parameterType.isCombo) {
        uiField.displayField = 'value';
        uiField.valueField = 'key';
        uiField.editable = false;
        uiField.store = Ext.create('Ext.data.Store', {
            fields: ['key', 'value'],
            data: el.parameterType.values
        });
    }
    return uiField;
}

and el parameter is a JavaScript object like that: el参数是这样的JavaScript对象:

{
    name: "",
    labelId: "Champ :",
    parameterType: {
        regEx: "^.*$",
        errID: "115",
        isCombo: true,
        values:[
            {key: "10", value: "etap 0"},
            {key: "200",value: "etape 1"},
            {key: "300",value: "etape 3"},
        ],
        selectedValue: "etap 0"
    },
    mandatory: false,
    visible: true,
    defaultValue: "",
    elementType: "LIST_BOX",
    regExErrMsg: "Valeur invalide.",
    requiredErrMsg: ""
}

and me.componentType at runtime is Ext.form.field.ComboBox 而运行时的me.componentTypeExt.form.field.ComboBox

This fiddle works fine for me, I removed the references to el as it shown undefined for me and also changed Ext.data.store to Ext.data.Store 这个小提琴对我来说很好用,我删除了对el的引用,因为它对我来说是未定义的,并且还将Ext.data.store更改为Ext.data.Store

https://fiddle.sencha.com/#fiddle/jj6 https://fiddle.sencha.com/#fiddle/jj6

Ext.application({
    name: 'Fiddle',

    launch: function() {
        Ext.create("Ext.form.field.ComboBox", {
            renderTo: Ext.getBody(),
            displayField: "value",
            valueField: "value",
            flex: 1,
            store: Ext.create("Ext.data.Store", {
                fields: ['key', 'value'],
                data: [{
                    key: "10",
                    value: "etap 0"
                }, {
                    key: "200",
                    value: "etape 1"
                }, {
                    key: "300",
                    value: "etape 3"
                }]
            })
        });
    }
});

valueField:“ value”是错误的,您应该指定valueField:“ key”才能使ComboBox正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM