2014-11-06 50 views
1

我尝试清除特定组合的值。有时会发生,有时不会。我尝试了不同的方法,但无济于事。现在,我不喜欢这样写道:如何清除组合?

mycombo.reset(); 
mycombo.clearValue(); 
mycombo.applyEmptyText(); 

是的,我的组合有forceSelection:true

我甚至检查这些代码三个“法宝”线:

mycombo.clearValue(); 
mycombo.applyEmptyText(); 
mycombo.getPicker().getSelectionModel().doMultiSelect([], false); 

但我仍然有相同的画面。组合的复位事出于偶然

回答

1

在组合有一个叫assertValue魔术方法,它往往会导致一些问题:

assertValue: function() { 
    var me = this, 
     value = me.getRawValue(), 
     rec, currentValue; 

    if (me.forceSelection) { 
     if (me.multiSelect) { 
      // For multiselect, check that the current displayed value matches the current 
      // selection, if it does not then revert to the most recent selection. 
      if (value !== me.getDisplayValue()) { 
       me.setValue(me.lastSelection); 
      } 
     } else { 
      // For single-select, match the displayed value to a record and select it, 
      // if it does not match a record then revert to the most recent selection. 
      rec = me.findRecordByDisplay(value); 
      if (rec) { 
       currentValue = me.value; 
       // Prevent an issue where we have duplicate display values with 
       // different underlying values. 
       if (!me.findRecordByValue(currentValue)) { 
        me.select(rec, true); 
       } 
      } else { 
       me.setValue(me.lastSelection); 
      } 
     } 
    } 
    me.collapse(); 
} 

基本上当你不使用multiSelect然后lastSelection总是使用,当您尝试在商店找不到的设定值。 我通常会添加虚拟记录来存储,这对应于空值。如果您需要将allowBlank设置为false,问题将会回来。

作为一种替代添加伪记录可以覆盖assertValue方法是这样的:

assertValue: function() { 
    var me = this, 
     value = me.getRawValue(); 

    if (me.forceSelection && me.allowBlank && Ext.isEmpty(value)) { 
     me.setValue(value); 
     me.collapse(); 
     return; 
    } 

    this.callParent(arguments); 
}