gpt4 book ai didi

javascript - ComboBox typeAhead 可以工作,但 valueField 在某些行为条件下为空

转载 作者:行者123 更新时间:2023-11-28 00:31:09 25 4
gpt4 key购买 nike

请在此处请求健全性检查...

ExtJS 4.2 组合框 Typeahead 可以工作,但在以下条件下检索 valueField 时出现问题:-

1) 如果用户键入一个值,然后单击其他位置而不是按 Enter 键或单击选择组合列表,则 valueField 为空,但会出现所选值。

2)假设组合框项目被正确选择,如果我输入一个附加字符然后退格该字符,组合框将无法再找到 valueField..它几乎就像重置了自己一样。

fiddle 示例

<强> https://fiddle.sencha.com/#fiddle/je1

如何重现

如果在组合框中输入 Maggie,您将在控制台窗口中看到 valueField ID,如果追加一个字符然后退格该字符,则控制台窗口中的 ID 为空

(您需要打开控制台窗 Eloquent 能查看输出)

forceSelection 无法解决此问题,因为我有一个模板,并且它不接受组合框中不属于商店的条目,并且我需要对 valueField 使用 sumID,因为我需要检索并传递该值到服务器。

最佳答案

谢谢大家,拥有如此出色的社区真是太棒了!

我能够通过使用forceSelection并覆盖setValue来解决这个问题,从而允许通过forceSelection选择不在商店中但在组合中的模板项。在我看来,从使用组合框开始,为了获得良好的外观和感觉,forceSelection 是最佳选择。

这是我的覆盖,请参阅语句//覆盖开始

这是一个快速修复,当我回到办公室时我会完善陈述,下面我将我凭内存粘贴的解决方案,你明白了。

setValue: function(value, doSelect) {
var me = this,
valueNotFoundText = me.valueNotFoundText,
inputEl = me.inputEl,
i, len, record,
dataObj,
matchedRecords = [],
displayTplData = [],
processedValue = [];

if (me.store.loading) {
// Called while the Store is loading. Ensure it is processed by the onLoad method.
me.value = value;
me.setHiddenValue(me.value);
return me;
}

// This method processes multi-values, so ensure value is an array.
value = Ext.Array.from(value);

// Loop through values, matching each from the Store, and collecting matched records
for (i = 0, len = value.length; i < len; i++) {
record = value[i];
if (!record || !record.isModel) {
record = me.findRecordByValue(record);
}
// record found, select it.
if (record) {
matchedRecords.push(record);
displayTplData.push(record.data);
processedValue.push(record.get(me.valueField));
}
// record was not found, this could happen because
// store is not loaded or they set a value not in the store
else {
//start of override

// 'Select All Names' is the template item that was added // to the combo box, it looks like an entry from the store
// but it is not in the store
if (me.forceSelection && me.getDisplayValue() === 'Select All Names'){
processedValue.push(value[i]);
dataObj = {};
dataObj[me.displayField] = value[i];
displayTplData.push(dataObj);
}
//end of override

if (!me.forceSelection) {
processedValue.push(value[i]);
dataObj = {};
dataObj[me.displayField] = value[i];
displayTplData.push(dataObj);
// TODO: Add config to create new records on selection of a value that has no match in the Store
}
// Else, if valueNotFoundText is defined, display it, otherwise display nothing for this value
else if (Ext.isDefined(valueNotFoundText)) {
displayTplData.push(valueNotFoundText);
}
}
}

// Set the value of this field. If we are multiselecting, then that is an array.
me.setHiddenValue(processedValue);
me.value = me.multiSelect ? processedValue : processedValue[0];
if (!Ext.isDefined(me.value)) {
me.value = null;
}
me.displayTplData = displayTplData; //store for getDisplayValue method
me.lastSelection = me.valueModels = matchedRecords;

if (inputEl && me.emptyText && !Ext.isEmpty(value)) {
inputEl.removeCls(me.emptyCls);
}

// Calculate raw value from the collection of Model data
me.setRawValue(me.getDisplayValue());
me.checkChange();

if (doSelect !== false) {
me.syncSelection();
}
me.applyEmptyText();

return me;
},

关于javascript - ComboBox typeAhead 可以工作,但 valueField 在某些行为条件下为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28979652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com