autocomplete - 将第一个字符与sql查询匹配

时间:2014-07-12 17:03:59

标签: php jquery sql jquery-autocomplete

我有以下代码:

$(function() {
//autocomplete
$("#autocomplete_ville_nom").autocomplete({
source: "../assets/php_queries/search_ville_nom.php",
minLength: 2
}); 
});

我正在尝试进行调整,以便在前两个字符上进行匹配。如果用户输入“An”,他应该看“安哥拉”,而不是“法国”。

我发现以下代码效果很好:

var wordlist= [ "about", "above", "across", "after", "against",
                "along", "among", "around", "at", "before", 
                "behind", "below", "beneath", "beside", "between", 
                "beyond", "but", "by", "despite", "down", "during", 
                "except", "for", "from", "in", "inside", "into", 
                "like", "near", "of", "off", "on", "onto", "out", 
                "outside", "over", "past", "since", "through", 
                "throughout", "till", "to", "toward", "under", 
                "underneath", "until", "up", "upon", "with", 
                "within", "without"] ; 

$("#input1").autocomplete({
    // The source option can be an array of terms.  In this case, if
    // the typed characters appear in any position in a term, then the
    // term is included in the autocomplete list.
    // The source option can also be a function that performs the search,
    // and calls a response function with the matched entries.
    source: function(req, responseFn) {
        var re = $.ui.autocomplete.escapeRegex(req.term);
        var matcher = new RegExp( "^" + re, "i" );
        var a = $.grep( wordlist, function(item,index){
            return matcher.test(item);
        });
        responseFn( a );
    } });

来自jQuery UI Autocomplete widget search configuration

然而,我找不到合并两者的方法(基本上使用我的php查询而不是列表)。

你能帮帮忙吗? 感谢

0 个答案:

没有答案