在运行时设置 extjs 6 组合框的存储数据导致显示错误

Setting an extjs 6 combobox's store data at runtime results in display error

我有一个组合框的原型,我试图在其中设置运行时的商店数据。

当我尝试执行此操作时,组合框下的菜单未呈现(或者它呈现得太小以至于您实际上看不到)。这是 here on sencha fiddle:

Ext.define('ComboBoxRates',{
    extend: 'Ext.data.Store',
    alias: 'store.rates',
    storeId: 'ratescombo',
    fields: ['rate', 'description', 'price' ]
});

Ext.define('ComboPanel',{
    extend: 'Ext.panel.Panel',
    title: 'Test',
    renderTo: Ext.getBody(),
    items:[
        {
            xtype: 'combobox',
            editable: false,
            displayField: 'description',
            valueField: 'price',
        }
    ]    
});


Ext.application({
    name : 'Fiddle',

    launch : function() {

        var data = [
            {
                description: "5: Standard Registration",
                price: "105",
                rate: "rate1"
            },
            {
                description: "5: Non-Member Rate",
                price: "125",
                rate: "rate2"
            },
            {
                description: ": Price for SK tester",
                price: "44",
                rate: "rate3"
            },
            {
                description: ": Another price :O",
                price: "11",
                rate: "rate5"
            }
        ];

        var rates = Ext.create('ComboBoxRates');

        rates.setData(data);

        // Showing data is loaded into the store
        console.group('directly from store instance');
        rates.each(function (rate){
           console.log(rate.getData());
        });
        console.groupEnd();

        var panel = Ext.create('ComboPanel');


        panel.down('combobox').setStore(rates);

        // Showing that the data is definitely in the widget's store        
        console.group('from widget store');
        panel.down('combobox').getStore().each(function (rate){
           console.log(rate.getData());
        });
        console.groupEnd();



    }
});

我知道数据已加载到组合框的存储中(在 fiddle 中打开控制台日志),所以我不确定为什么它无法正确呈现。

我知道在这种情况下这看起来很愚蠢,但原型是从网格的小部件列中提取的逻辑,其中每一行都有不同的存储数据。

我还构建了一个具有相同结构的 one-step-back prototype,但相同的数据内嵌在商店的定义中并且有效:

Ext.define('ComboBoxRates',{
    extend: 'Ext.data.Store',
    alias: 'store.rates',
    storeId: 'ratescombo',
    fields: ['rate', 'description', 'price' ],
    data: [
        {
            description: "5: Standard Registration",
            price: "105",
            rate: "rate1"
        },
        {
            description: "5: Non-Member Rate",
            price: "125",
            rate: "rate2"
        },
        {
            description: ": Price for SK tester",
            price: "44",
            rate: "rate3"
        },
        {
            description: ": Another price :O",
            price: "11",
            rate: "rate5"
        }
    ]
});

Ext.define('ComboPanel',{
    extend: 'Ext.panel.Panel',
    title: 'Test',
    renderTo: Ext.getBody(),
    items:[
        {
            xtype: 'combobox',
            editable: false,
            displayField: 'description',
            valueField: 'price',
        }
    ]    
});


Ext.application({
    name : 'Fiddle',

    launch : function() {


        var rates = Ext.create('ComboBoxRates');

        var panel = Ext.create('ComboPanel');

        panel.down('combobox').setStore(rates);
    }
});

我认为 updateLayout 可以解决问题,但事实并非如此。

我的代码有问题吗?有什么方法可以在运行时设置组合框的值吗?

您缺少 queryMode,请在组合中使用 queryMode: 'local'

工作示例:https://fiddle.sencha.com/#fiddle/10al