ExtJS 6:TreePicker不会触发更改事件

时间:2018-06-27 01:14:06

标签: events extjs extjs6 extjs6-classic treepanel

在这里查看小提琴: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;
    }
});

1 个答案:

答案 0 :(得分:2)

因为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;
},
相关问题