jQueryUI自動検索機能にいくつかの機能を追加する必要があります。私が解決したい問題は、ユーザーが用語のリストを検索して提案を表示する任意の順序でテキストを入力できるようにすることです。たとえば、次の用語があるとします。
the brown cow jumped over the moon
the blue cow watched in horror
the red cow simply laughed
the green cow got sick at such a sight
the yellow cow lost 5 bucks to the black cow
the black cow smiled at his fortune
If the user types in "the cow", I would expect the autocomplete feature to list all the results.
If I type in "brown moon", I would expect the first result to appear.
If I type in "fortune smiled", the last result would appear.
基本的に、この動作により、ユーザーは任意の文字列を任意の順序で入力して検索結果を取得できます。
これが私が考えていることです。「open」または「search」イベントのいずれかにコールバック関数を追加し、そこで結果を操作する必要があります。これまでの私のコードは次のとおりです。
$(function ()
{
var data =
[
"the brown cow jumped over the moon",
"the blue cow watched in horror",
"the red cow simply laughed ",
"the green cow got sick at such a sight",
"the yellow cow lost 5 bucks to the black cow",
"the black cow smiled at his fortune"
];
$(".text-search").autocomplete(
{
autoFocus: true,
source: data,
delay: 0,
minLength: 2,
open: function (e, ui)
{
debugger;
// what should i do here?
},
search: function (e, ui)
{
debugger;
// what should i do here?
}
});
});
<div class="ui-widget">
<label for="autocomplete">Autocomplete: </label>
<input class="text-search">
</div>