How to customize the jquery autocomplete search mechanism -
i want customize search behavior of jquery autocomplete, existing code below
var data = [ {"url":"http://site/test.php", "label":" test course"}] $k(".input").autocomplete({ max:10, source: data, multipleseparator: " ", select: function( event, ui ) { window.location.href = ui.item.url; }, appendto: "#results", open: function() { var position = $("#results").position(), left = position.left, top = position.top; $("#results > ul").css({left: left + 20 + "px", top: top + 4 + "px" }); } });
i need ignore white spaces in data (search data).
suppose if type "testcourse", must result "test course".
how this.
duplicate values in data
have white-space same entry label
being different (without white-space).
var data = [ {"url":"http://site/test.php", "label":" test course"}, {"url":"http://site/test.php", "label":" testcourse"} ];
here's way can loop through data
, add items not same when strip out white-spaces:
for(i = 0; < data.length; i++){ var nowhsp = data[i].label.replace(/\s/g, ''); if(data[i].label !== nowhsp){ data.push({"url":data[i].url, "label":nowhsp}) } }
Comments
Post a Comment