2014-11-06 46 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); 
}