ExtJS 4 组合框自动完成

标签 extjs autocomplete combobox extjs4

我有一个用于自动完成的 extjs 组合框,具有以下配置:

xtype:'combo',
displayField: 'name',
valueField:'id',
store: storeVar,
queryMode: 'remote',
minChars:2,
hideTrigger:true,
forceSelection:true,
typeAhead:true

我面临两个问题:

一种。 如果用户从服务器返回的列表中选择一个值,但稍后想要删除该值并将组合框保持为空,那么旧值也会重新出现在模糊中,不允许组合框保持为空。在这种情况下,如何在此组合框中允许空值? 我知道这可能是由于 forceSelection:true,但是我需要保持它真实,否则用户可以输入任何随机值。

当服务器返回一个空列表时,我想显示一条消息 - No Values Found .我尝试这样做,将这个值放在 displayField 实体中,即 {id:'', name:'No Value Found'}。但是在这种情况下,用户可以选择这个值并将其发送到服务器,这不是预期的。因此,如何显示空列表的消息?

有人可以对此有所了解吗?

最佳答案

对于上述问题中与 forceSelection 相关的问题,以下是创建的可以达到预期目的的 hack:

Ext.override(Ext.form.field.ComboBox,{          
    assertValue: function() {
        var me = this,
            value = me.getRawValue(),
            rec;
        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) {
                me.select(rec);
            } else {
                if(!value){
                    me.setValue('');
                }else{
                    me.setValue(me.lastSelection);
                }
            }
        }
        me.collapse();
    }
});

这需要在包含 extjs 的库文件后包含。

对于在 No Values Found - emptyText 中显示的另一个消息问题,按照 Varun 的建议工作正常。

希望这可以帮助某人寻找类似的东西。

关于ExtJS 4 组合框自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7345922/

相关文章:

javascript - 显示 2 个按钮的 Ajax 组合框

extjs - 我们可以在 sencha touch 中将转换后的 Base64 图像调整为自定义尺寸吗

javascript - 将焦点设置在 Extjs 文本字段上

c++ - 如何在 emacs 中使用公司模式、irony 后端和 irony header

c# - 带有固定标题的 ComboBox

c# - WPF ComboBox BorderBrush 不会改变

javascript - 如何检查是否在文本区域上按下了 Shift+Enter

javascript - 我如何将 loadData 函数作为 Ext.data.JsonStore ExtJS3.0.0 的一部分?

python - spy 程序不会自动完成新的解释器(virtualenv)

jquery - 全局位置输入自动完成