ExtJS 6: TreePicker не запускает событие изменения - PullRequest
0 голосов
/ 27 июня 2018

См. Скрипку здесь: 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' срабатывает, как и ожидалось, но срабатывает только тогда, когда пользователь выбирает поле.

EDIT:

Основываясь на предложении Снежала, приведенном ниже, я смог выполнить это с помощью следующего переопределения. Не уверен, что есть более простой способ сделать это, но это было лучшее, что я мог сделать:

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 голосов
/ 27 июня 2018

Потому что 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;
},
...