【问题标题】:Algolia JavaScript call the search for autocompleteAlgolia JavaScript 调用自动完成搜索
【发布时间】:2019-03-15 20:56:25
【问题描述】:
var client = algoliasearch(algClient, apiKey);
var index = client.initIndex(algIndex);
var paintingAutocomplete = {
  source: autocomplete.sources.hits(index, { hitsPerPage: 4 }),
  displayKey: "title",
  templates: {
    header: '<div class="ad-example-header">Painting</div>',
    suggestion: function(suggestion) {
      console.log(suggestion);

      return (
        '<img class="search-thumbnail" src="https://res.cloudinary.com/b3/h_360/' +
        suggestion["field_file_name:file"] +
        '" />' +
        suggestion.title
      );
    }
  }
};

var autocompleteInstance = autocomplete(
  document.querySelector("#search-input"),
  {
    hint: false,
    debug: true,
      cssClasses: { prefix: 'ad-example'}
  },
  [
    paintingAutocomplete,
  ]
).on("autocomplete:selected", function(event, suggestion) {
    // console.log(suggestion, );
});

var autocompleteChangeEvents = ["selected", "autocompleted"];

autocompleteChangeEvents.forEach(function(eventName) {
  autocompleteInstance.on("autocomplete:" + eventName, function(event, suggestion, datasetName) {
    // Call the search here...
  });
});

search.start();

我正在搜索绘画并使用 algolia api、instantsearch 和 autocomplete.js。我已经添加了自动完成,但选择自动完成的答案时结果没有更新。如何在选择项目时从 Instantsearch 调用搜索小部件。目前它只搜索我在搜索框中输入的内容。

【问题讨论】:

    标签: javascript autocomplete algolia instantsearch.js


    【解决方案1】:

    这里是带有自动完成功能的沙盒作为灵感搜索框:https://codesandbox.io/s/y79ww39xyv

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      相关资源
      最近更新 更多