ExtJS 4 ComboBox自动完成

net*_*emp 5 combobox extjs autocomplete extjs4

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

xtype:'combo',
displayField: 'name',
valueField:'id',
store: storeVar,
queryMode: 'remote',
minChars:2,
hideTrigger:true,
forceSelection:true,
typeAhead:true
Run Code Online (Sandbox Code Playgroud)

我面临两个问题:

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

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

有人可以点亮这个吗?

net*_*emp 3

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

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();
    }
});
Run Code Online (Sandbox Code Playgroud)

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

对于在“找不到值”处显示的另一期消息 - 空文本 - 按照 Varun 的建议工作正常。

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