質問

I am passing an static array to jquery token input but the search results are not exact match because there is no server side query's..

like for an array ['aa','bab','aab','abb'] if I type ab I'm getting 'bab' before 'abb' and 'aab'.

can anyone help me to solve this issue..

Thank you in advance.

役に立ちましたか?

解決

I'm not entirely sure how you wish to rank your results, at first I thought you wanted items that start with a string to be at the top, but then I don't see how 'aab' should come before 'bab' for the search query 'ab'.

Regardless, I think you have a few options, if you want to order the results based on the search query.

The first, which I would recommend, would be to build a server side script to handle this. It's a simple matter of pulling any exact matches to be the first item in the JSON array you'd need to return. This is the un-hacky way to go about it!

The second, if you decidedly wanted to keep it all client-side, would be to reorder your results array at the start of the populateDropdown method in the library (c. line 843)

Finally, and the most elegant, and 'correct' way, would be to reconfigure the onResult callback to also take the search query as a parameter, where you could then sort out the ordering of your results using the callback method.

Hope this gives some food for thought, good luck!

他のヒント

I have taken two search items and the match is on the first letter of each word. Limiting to 15 results. This is giving perfect results for me.

//Do the search through local data
var results = $.grep(array, function (row) {
  return row["id"].toLowerCase().indexOf(term.toLowerCase()) > -1;
});
var results1="";
if(results.length<15){
   results1 = $.grep(array, function (row) {
   return row["value"].toLowerCase().indexOf(term.toLowerCase()) > -1;
});
}
var diff = $(results1).not(results).get();
results= $.merge( $.merge([],results), diff);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top