在组合有一个叫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);
}