代码之家  ›  专栏  ›  技术社区  ›  zeke

extjs 6:treepicker不触发更改事件

  •  2
  • zeke  · 技术社区  · 6 年前

    请看这里的小提琴: https://fiddle.sencha.com/#fiddle/2iig&view/editor

    文件( https://docs.sencha.com/extjs/6.6.0/classic/Ext.ux.TreePicker.html#event-change )列表 'change' 在events部分中,但是当我设置值或重置字段时,此事件不会触发。这个 '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;
        }
    });
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Rohit Sharma    6 年前

    因为 setValue 函数不调用 this.callParent() 是的。你可以在里面做这样的事 设定值 功能。

    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;
    },