在 Enter 命中时使用组合框进行远程查询

Remote query with combobox on Enter hit

我有一个带有远程存储的组合框。当用户写下三个或更多字母时,我会看到一个服务器请求,但我想在用户点击 Enter 按钮时触发此请求。此时我的组合具有这些属性:

forceSelection:true,
enableKeyEvents:true,
listeners:{
    keyup:function(){ // I prevent "normal" server requests in this manner
        return false;
    },
    keydown:function(){
        return false;
    },
    keypress: function() {
        return false;
    },
    specialkey:function(a,b,c){
        if(b.keyCode==13){
            // But at this moment I want to make a request          
        }
    }
}

您可以将 'minChars' 设置为一个非常高的值,以在键入时禁用值选择。 http://docs.sencha.com/extjs/4.2.3/#!/api/Ext.form.field.ComboBox-cfg-minChars

然后在回车键上展开组合框选择:

forceSelection:true,
enableKeyEvents:true,
// show value selection after typing 999 chars
minChars: 999,
// set triggerAction to 'query' to show only filtered results after pressing enter
triggerAction: 'query',
listeners: {
    specialkey: function (combobox, e) {
        if (e.keyCode == 13) {
            combobox.expand();
        }
    }
}