最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery Autocomplete Custom Lookup Function - Stack Overflow

programmeradmin6浏览0评论

I want to use jquery.autoplete.js plugin for an input in my form. I want to search on the client side and can't use ajax. But I don't want some simple "Contains"-based search algorithm within an array. What I want to do is to write a custom search function in javascript to search and order the results. Is this even possible and how?

Thanks for your time.

I want to use jquery.autoplete.js plugin for an input in my form. I want to search on the client side and can't use ajax. But I don't want some simple "Contains"-based search algorithm within an array. What I want to do is to write a custom search function in javascript to search and order the results. Is this even possible and how?

Thanks for your time.

Share Improve this question asked Sep 14, 2013 at 6:25 HoseinHosein 5811 gold badge7 silver badges29 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

It surely is. You specify source to be a function which will answer a list of strings or alternatively {label, value} objects.

$('#myInput').autoplete({
    source: function (request, response) {
        var term = request.term;
        var data = handleAutoplete( term);  /* get answers from somewhere.. */
        response( data);
    }
});

function handleAutoplete (term) {
    var options = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"];
    // use 'term' for custom filtering etc.
    return options;
}

See: http://api.jqueryui./autoplete/#option-source

发布评论

评论列表(0)

  1. 暂无评论