【问题标题】:Extjs 4.1 Combo - How to make select function fire When call combo.setValueExtjs 4.1 Combo - 如何在调用 combo.setValue 时触发选择函数
【发布时间】:2013-08-09 04:40:20
【问题描述】:

我有一个类似的组合

        items: {  
            xtype: 'combo',
            id: 'combo',
            queryMode: 'local',                
            displayField: 'name',
            valueField: 'id',
            store: Ext.create('Ext.data.Store', {
                fields: ['id', 'name', 'mydata'],
                data: [
                  {'id': '1', 'name': 'John Smith', 'mydata': ["3", "4"]},
                  {'id': '2', 'name': 'Albert Einstein', 'mydata': ["1", "2"]}
                ]
            }),
            listeners: {
               select: function( combo, records, eOpts ) {
                    alert(records[0].get('mydata')); // records is undefined
               }
            }
        }

但是当我使用时

    var combo = Ext.getCmp('combo');
    //combo.select("1");
    combo.setValue("1");
    combo.fireEvent('select');

然后alert(records[0].get('mydata')); // records is undefined 失败。如何解决这个问题谢谢。
这是我的代码http://jsfiddle.net/LZ8XU/

【问题讨论】:

    标签: extjs extjs4.1


    【解决方案1】:

    由于某种原因,Ext 组合框的 select 方法不会触发 select 事件。在我看来,您想设置一个值并手动触发 select 事件。如果是这样,还有几个字段需要通过;特别是组合框本身和选定的记录。

    这是一个实现它的实现。

    var combo = Ext.getCmp('combo');
    var toselect = "Albert Einstein";
    
    combo.select(toselect);
    var record = combo.getStore().findRecord('name', toselect);
    combo.fireEvent('select', combo, [record]);
    

    【讨论】:

    • 没错,调用select()方法时不会自动触发select事件。它们应该像按钮的切换方法一样包含一个 suppressEvent 布尔参数。
    • @Kyle Fransham:你能帮我处理一下stackoverflow.com/questions/21521112/…
    【解决方案2】:

    为什么不听change 事件呢?

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 2015-11-27
    • 2018-11-04
    • 1970-01-01
    相关资源
    最近更新 更多