Extjs 如何清除组合?
我试图清除特定组合的值。有时会发生,有时不会。我尝试了不同的方法,但没有用。现在,我这样做:Extjs 如何清除组合?,extjs,extjs4.1,Extjs,Extjs4.1,我试图清除特定组合的值。有时会发生,有时不会。我尝试了不同的方法,但没有用。现在,我这样做: mycombo.reset(); mycombo.clearValue(); mycombo.applyEmptyText(); assertValue: function () { var me = this, value = me.getRawValue(); if (me.forceSelection && me.allowBlank &
mycombo.reset();
mycombo.clearValue();
mycombo.applyEmptyText();
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);
}
是的,我的组合有forceSelection:true
我甚至检查了这三行“神奇”的代码:
mycombo.clearValue();
mycombo.applyEmptyText();
mycombo.getPicker().getSelectionModel().doMultiSelect([], false);
但我仍然有同样的照片。组合的重置是偶然发生的在组合中有一种叫做
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
方法,如下所示:
mycombo.reset();
mycombo.clearValue();
mycombo.applyEmptyText();
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);
}