https://www.algolia.com/doc/search/auto-completeに基づいて独自のAlgolia PoCを実装しましたが、特定のユースケースに苦しんでいます。ヒットを返さない検索はどのように処理できますか?ここでヒットが返されない場合はAlgoliaテンプレート
は私のコードです:
)私はヒットが返されないところとき/識別して検出することができましたが、私はちょうど(はconsole.logを使用して横に何もすることはできません。私はカスタムreturn_msgを取得しようとしましたが、私は関数を呼び出すことはできません。 私はまた、提案の下でいくつかの微調整を試みました:関数(提案)しかし、ヒットが返されない場合、この関数は呼び出されません。 は、私はまた、あなたがするときに使用するテンプレートを指定することができ、あなたのデータセットのtemplates
オプションを使用して任意のポインタをいただければ幸いですhttps://github.com/algolia/autocomplete.js
$('#q').autocomplete({ hint: false }, [
{
source: function(q, cb) {
index.search(q,
{ hitsPerPage: 10 },
function(error, content) {
if (error) {
cb([]);
return;
}
if (content.nbHits == 0)
{ return_msg = '<h5> Sorry, no result </h5>';
// DO something here
console.log(return_msg);
// console.log return "Sorry, no result"
}
cb(content.hits, content);
});
},
displayKey: 'game',
templates: {
suggestion: function(suggestion) {
return_msg = '<h5> '+ suggestion.MY_ATTRIBUTE + '</h5>'
return return_msg;
}
}
}
]).on('autocomplete:selected', function(event, suggestion, dataset) {
window.location = (suggestion.url);
});
=)
ありがとうございます - 完璧に動作しています。どうして私がドキュメントでそれらを見逃したのかわかりません:/ – PERPO