【问题标题】:ExtJS 6: TreePicker does not fire change eventExtJS 6:TreePicker 不会触发更改事件
【发布时间】:2018-06-27 01:14:05
【问题描述】:

在此处查看小提琴:https://fiddle.sencha.com/#fiddle/2iig&view/editor

文档 (https://docs.sencha.com/extjs/6.6.0/classic/Ext.ux.TreePicker.html#event-change) 在事件部分列出了'change',但是当我设置值或重置字段时,此事件永远不会触发。 'select' 事件按预期触发,但仅在用户选择字段时触发。

编辑:

根据以下 Snehal 的建议,我能够使用以下覆盖来完成此操作。不确定是否有更简单的方法,但这是我能做到的最好的方法:

Ext.define('MyApp.overrides.TreePicker', {
    override: 'Ext.ux.TreePicker',

    setValue: function (value) {
        var me = this,
            record;
        me.value = value;
        if (me.store.loading) {
            // Called while the Store is loading. Ensure it is processed by the onLoad method.
            return me;
        }
        // try to find a record in the store that matches the value
        record = value ? me.store.getNodeById(value) : me.store.getRoot();
        if (value === undefined) {
            record = me.store.getRoot();
            me.value = record.getId();
        } else {
            record = me.store.getNodeById(value);
        }

        // zeke - this is the only line I added to the original source
        // without this the 'change' event is not fired
        me.callSuper([value]);

        // set the raw value to the record's display field if a record was found
        me.setRawValue(record ? record.get(me.displayField) : '');

        return me;
    }
});

【问题讨论】:

    标签: events extjs extjs6 extjs6-classic treepanel


    【解决方案1】:

    因为setValue 函数没有调用this.callParent()。你可以在setValue函数中做这样的事情。

    setValue: function(value) {
        var me = this,
            record;
        if (me.store.loading) {
            // Called while the Store is loading. Ensure it is processed by the onLoad method.
            return me;
        }
    
        // try to find a record in the store that matches the value
        record = value ? me.store.getById(value) : me.store.getRoot();
    
        me.callParent([record.get('valueField')]);
        return me;
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-11
      • 1970-01-01
      • 2021-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多