I次の検索コードを持っている:Algoliaオートコンプリート問題
autocomplete('#search-input', {hint: false, autoselect: true}, [
{
source: autocomplete.sources.hits(contacts, { hitsPerPage: 3 }),
displayKey: 'CustomerName',
templates: {
header: '<div class="leftMargin5"><b>Contacts</b></div>',
suggestion: function(hit) {
return templateContact.render(hit);
}
}
},
{
source: autocomplete.sources.hits(products, { hitsPerPage: 5 }),
displayKey: 'ProductDescription',
templates: {
header: '<div class="leftMargin5"><b><Products</b></div>',
suggestion: function(hit) {
return templateProduct.render(hit);
}
}
}
]).on('autocomplete:selected', function (event, suggestion, dataset) {
//DoSomething
}).on('autocomplete:autocompleted', function (event, suggestion, dataset) {
//DoSomething
});
私の問題は、私は、検索ボックスに入力を開始するとき、先頭の要素が選択され、検索ボックス内のテキストは、この試合に設定されていることです。検索ボックスにテキストを入力したり削除したりすることができません。入力または削除するだけで元の一致が選択されます。
最初のヒットを強調表示して入力時に選択するようにしようとしていますが、私が探しているものがトップでない場合は、入力を続けたり別のアイテムを選択したりできます。
オプションを削除すると、検索ボックスは機能しますが、もちろん自動選択機能はありません。
フィドルを作成できますか?これは私たちが多くの助けになるのに役立ちます。 – Jerska