自动完成 - 显示整个列表

mar*_*zzz 5 jquery jquery-ui autocomplete click jquery-ui-autocomplete

我有这个代码:

var myList = [ "Avellino", "Enna", "Frosinone" ];

myInput.autocomplete({
    source: function(request, response) {            
        var data = $.grep(myList, function(value) {
            return value.substring(0, request.term.length).toLowerCase() == request.term.toLowerCase();
        });            

        response(data);
    },        
    appendTo: "#myDiv"
});
Run Code Online (Sandbox Code Playgroud)

我想,当我点击输入框时,显示所有元素的列表(使用相同的自动完成框选择值)myList.

我想我需要第三部分处理程序,例如:

myInput.focus(function () {

});
Run Code Online (Sandbox Code Playgroud)

但我不知道如何与自动完成对话.任何想法/解决方案?

And*_*ker 14

@jasonlfunk就在那里 -你必须调用search自动完成小部件focus才能使它工作:

var myList = [ "Avellino", "Enna", "Frosinone" ];

$('#myInput').autocomplete({
    minLength: 0,
    source: function(request, response) {            
        var data = $.grep(myList, function(value) {
            return value.substring(0, request.term.length).toLowerCase() == request.term.toLowerCase();
        });            

        response(data);
    }
}).focus(function () {
    $(this).autocomplete("search", "");
});
Run Code Online (Sandbox Code Playgroud)

示例: http ://jsfiddle.net/BRDBd/


jas*_*unk 5

查看自动完成插件的minLength选项。将它设置为零应该做你想做的。

var myList = [ "Avellino", "Enna", "Frosinone" ];

myInput.autocomplete({
    minLength: 0,
    source: function(request, response) {            
        var data = $.grep(myList, function(value) {
            return value.substring(0, request.term.length).toLowerCase() == request.term.toLowerCase();
        });            

        response(data);
    },        
    appendTo: "#myDiv"
}).focus(function(){
    $(this).autocomplete("search",$(this).val());
});?;
Run Code Online (Sandbox Code Playgroud)