开发者

jQuery autocomplete: matchContains not working

I have jQuery and the autocomplete plugin setup. Autocomplete works fine and various options I set like width and lookup work okay. But the one thing that does not work is the matchContains option. According to the doc "Whether or not the comparison looks inside (i.e. does "ba" match "foo bar") the search results. Important only if you use caching. Don't mix with autofill." But it is not looking inside the search results. For example, "ba" will not find "foo bar".

<script type="text/javascript" src="styles/prosilver/template/jquery.js"></script>
<script type="text/javascript" src="styles/prosilver/template/jquery.autocomplete.js"></script>


<script type="text/javascript">
// <![CDATA[

/* Zeno */
function translatestyle(text)
{
    var val = document.getElementById('query').value;
    var lang = '{S_USER_LANG}'.substring(0,2);
    var list = "{TRANS_LIST}";
    var arr = list.match(val);
    if ( arr == null )
    {
      alert('That is not a valid translation term.');
    }
    else
    {
      insert_text('[translate='+lang+']'+val+'[/translate]');
      document.forms[form_name].elements[text_name].focus();
    }
}


  var a2;

  jQuery(function() {

    var onAutocompleteSelect = function(value, data) {
      $('#selection').html('<img src="\/global\/flags\/small\/' + data + '.png" alt="" \/> ' + value);
      alert(data);
    }

    var options = {
      serviceUrl: '/projects/autocomplete/service/autocomplete.ashx',
      matchContains: true,
      width: 300,
      delimiter: /(,|;)\s*/,
      onSelect: onAutocompleteSelect,
      deferRequestBy: 0, //miliseconds
    };

    a2 = $('#query').autocomplete({
      matchContains: true,
      width: 300,
      delimiter: /(,|;)\s*/,
      lookup: "{TRANS_LIST}".split(',')
    });


    $('#navigation a').eac开发者_如何学运维h(function() {
      $(this).click(function(e) {
        var element = $(this).attr('href');
        $('html').animate({ scrollTop: $(element).offset().top }, 300, null, function() { document.location = element; });
        e.preventDefault();
      });
    });

  });


I'm not familiar with that particular plugin, but you may want to try switching to the JQuery UI Autocomplete library. It's quite good, and does search inside the way you want.


Checkout this website. its got a working example and codes for it. http://www.ajaxdaddy.com/demo-jquery-autocomplete.html

what i think: what you are missing might be the onfindvalue event and method to handle the event


Example:

source: function (request, response) { // Contains
    var searchString = request.term,
        items = [];

    // OPTIONS
    // Search for items with "searchString"...
    // Example:
    items.push('test 1');
    items.push('foo');
    items.push('var');

    response(items); // Items
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜