Extjs 5/6:在标记字段中已选择的项目中选择项目时触发的事件

Extjs 5/6: event to fire when an item is selected among the already selected items in the tagfield

我有一个标签域可以从商店中选择多项商品。我想检测所有选定项目中的一个,我单击并突出显示其中一个选定值。

这是fiddle附件

https://fiddle.sencha.com/#fiddle/17or

不知道,但应该很容易找到:

  • 如果查看生成的标记,会发现所选项目具有 class x-tagfield-item-selected.
  • 如果您在 ExtJS 代码库中搜索 tagfield-item-selected,发现 tagSelectedClsExt.baseCSSPrefix + 'tagfield-item-selected'
  • 如果你在 ExtJS 代码库中搜索 tagSelectedCls,发现它在 xtemplate 中使用:

        me.multiSelectItemTpl = new Ext.XTemplate([
            '<tpl for=".">',
                '<li data-selectionIndex="{[xindex - 1]}" data-recordId="{internalId}" class="' + me.tagItemCls + childElCls,
                '<tpl if="this.isSelected(values)">',
                ' ' + me.tagSelectedCls,
                '</tpl>',
    

    其中有一个函数isSelected:

    isSelected: function(rec) {
        return me.selectionModel.isSelected(rec);
    },
    
  • 您很有可能 me.selectionModel 处引用的 selectionModel 是 ExtJS 的标准选择模型,因此它可能有一个事件 selectionchange。让我们试试:

    var tagfield = Ext.create('Ext.form.field.Tag', {
    ...
    });
    tagfield.selectionModel.on('selectionchange',function() {console.log('selectionchange')});
    

    有效。