Extjs 现代7.0组合框在每次值更改时触发“选择”事件
modern中的combobox会在每次输入更改时触发select事件。这与经典非常不同。这样做就无法区分用户进行选择和实际设置字段值 这在Sencha论坛上被报告为一个bug: 上面的链接还包含一个小提琴手来演示这个问题 有人遇到过这个问题吗?您是如何克服的?forceSelection:true将有助于解决此问题,但在不需要强制选择的情况下不会取消此错误 编辑: 此行为是由于此中的方法syncValue搜索导致的-方法是私有的,没有文档 我不明白为什么组件开发人员选择创建一个记录,即使它不存在 源文件中的注释: 要么用户键入了isInput,要么我们将setValue设置为存储区中不匹配的值,而我们不是forceSelection:true。我们创造了一个新记录 我建议使用以下覆盖来修复此行为:Extjs 现代7.0组合框在每次值更改时触发“选择”事件,extjs,extjs6-modern,extjs7,Extjs,Extjs6 Modern,Extjs7,modern中的combobox会在每次输入更改时触发select事件。这与经典非常不同。这样做就无法区分用户进行选择和实际设置字段值 这在Sencha论坛上被报告为一个bug: 上面的链接还包含一个小提琴手来演示这个问题 有人遇到过这个问题吗?您是如何克服的?forceSelection:true将有助于解决此问题,但在不需要强制选择的情况下不会取消此错误 编辑: 此行为是由于此中的方法syncValue搜索导致的-方法是私有的,没有文档 我不明白为什么组件开发人员选择创建一个记录,即使它不存
感谢您的回复,是的,这似乎阻止了每次输入更改都触发select。在我的特定场景中,我需要forceSelection:true。当我将记录加载到表单中时,我使用模拟记录设置combobox的初始值。该初始值集触发select,但在经典中不会这样做。我的控制器代码既适用于经典,也适用于现代,因此现代组合框打破了我的共享逻辑。奇怪的是,它没有默认值。很高兴为您提供帮助,欢迎来到StackOverflow。如果此答案或任何其他答案解决了您的问题,请将其标记为已接受。combobox组件有许多问题,很难将其全部准确定位。到目前为止,Combobox是我必须覆盖和更改行为最多的组件。
Ext.define('Ext.field.SelectOverride', {
override: 'Ext.field.Select',
autoCreateRecord: false,
syncValue: function() {
var me = this,
store = me.getStore(),
forceSelection = me.getForceSelection(),
valueNotFoundText = me.getValueNotFoundText(),
is, isCleared, isInput, value, matchedRecord;
if (me.reconcilingValue || !store || !store.isLoaded() || store.hasPendingLoad()) {
return;
}
me.reconcilingValue = true;
me.getSelection(); // make sure selection config is flushed
is = {};
is[me.syncMode] = true;
value = ((isInput = is.input || is.filter)) ? me.getInputValue() : me.getValue();
isCleared = value == null || value === '';
if (!isCleared) {
if (me.getMultiSelect()) {
return me.syncMultiValues(Ext.Array.from(value));
}
matchedRecord = (isInput ? store.byText : store.byValue).get(value);
if (matchedRecord) {
if (!matchedRecord.isEntity) {
matchedRecord = matchedRecord[0];
}
}
else if (!forceSelection) {
matchedRecord = me.findRecordByValue(value);
}
}
// Either user has typed something (isInput), or we've had a setValue
// to a value which has no match in the store, and we are not forceSelection: true.
// We create a new record.
if (!isCleared && !matchedRecord && !forceSelection && me.autoCreateRecord) {
matchedRecord = me.createEnteredRecord(value);
}
else {
if (isInput || is.store) {
if (!matchedRecord && forceSelection) {
me.setValue(null);
me.setSelection(null);
if (!is.filter) {
me.setFieldDisplay();
}
}
} else {
if (isCleared) {
if (me.mustAutoSelect()) {
matchedRecord = store.first();
if (me.getAutoSelect() === 'initial') {
me.setAutoSelect(false);
}
}
else {
me.setSelection(null);
}
}
else if (!matchedRecord && valueNotFoundText) {
me.setError(valueNotFoundText);
}
}
}
if (matchedRecord) {
me.setSelection(matchedRecord);
}
me.reconcilingValue = false;
}
});