2

我有一个组合框的原型,我试图在运行时设置存储数据。

当我尝试执行此操作时,组合框下的菜单不会呈现(或者它呈现得太小以至于您实际上看不到它)。它在 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: "$105: Standard Registration",
                price: "105",
                rate: "rate1"
            },
            {
                description: "$125: Non-Member Rate",
                price: "125",
                rate: "rate2"
            },
            {
                description: "$44: Price for SK tester",
                price: "44",
                rate: "rate3"
            },
            {
                description: "$11: 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();



    }
});

我知道数据已加载到组合框的存储中(打开小提琴中的控制台日志),所以我不确定为什么它不能正确渲染。

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

我还构建了一个具有相同结构的单步回原型,但相同的数据被内联在商店的定义中并且有效:

Ext.define('ComboBoxRates',{
    extend: 'Ext.data.Store',
    alias: 'store.rates',
    storeId: 'ratescombo',
    fields: ['rate', 'description', 'price' ],
    data: [
        {
            description: "$105: Standard Registration",
            price: "105",
            rate: "rate1"
        },
        {
            description: "$125: Non-Member Rate",
            price: "125",
            rate: "rate2"
        },
        {
            description: "$44: Price for SK tester",
            price: "44",
            rate: "rate3"
        },
        {
            description: "$11: 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 可以解决问题,但事实并非如此。

我的代码有问题吗?有没有办法在运行时设置组合框的值?

4

1 回答 1

2

你不见了queryModequeryMode: 'local'在组合中使用。

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

于 2015-10-30T06:34:08.920 回答