代码之家  ›  专栏  ›  技术社区  ›  Prince of Sweet heart

更改事件不适用于selectfield?

  •  1
  • Prince of Sweet heart  · 技术社区  · 10 年前

    我对sencha触摸选择字段更改事件感到震惊。通常的更改事件工作正常。但是在这样的选项值的情况下,

    {
         xtype: 'selectfield',
         label: 'Choose one',
         options: [{text: 'First Option',  value: 1},
                   {text: 'First Option', value: 2},
                   {text: 'Third Option',  value: 3}],
         listeners : {
              change : function (selectField, newValue, oldValue)
              {
                   console.log(newValue);
              }
         }
    }
    

    当本例值不同但显示值相同时,更改事件不起作用。请帮助完成此问题。

    1 回复  |  直到 10 年前
        1
  •  2
  •   Mohit Saxena    10 年前

    这是Sencha的问题。你可以检查这个链接

    https://www.sencha.com/forum/showthread.php?304198-Select-field-not-firing-change-event-on-same-text-but-different-value .

    但若你们需要这样做,那个么你们可以这样做,在launch函数中写下这个。

    Ext.override(Ext.field.Input, {
            setValue: function (newValue) {
                var oldValue = this._value;
    
                this.updateValue(this.applyValue(newValue));
    
                newValue = this.getValue();
                this.onChange(this, newValue, oldValue);
    
                return this;
            }
        });