ExtJS 6:TreePicker 不触发更改事件

ExtJS 6: TreePicker does not fire change event

请在此处查看 fiddle: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;
    }
});

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