algolia instantsearch.js searchBox小部件indexName错误

时间:2015-12-28 23:05:38

标签: algolia

我使用来自Algolia instantsearch.js的searchBox小部件收到错误错误消息显示:

indexName无效

这个错误很奇怪,因为它不仅存在,而且还显示结果!每次我在searchBox小部件中输入内容时,问题都会重复,并且结果不会被我输入的内容过滤掉。我创造了一个吸血鬼,看看是否有人能告诉我我做错了什么。

http://plnkr.co/edit/ihz5VMZ6HUDaYKTqwo9V?p=preview

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" href="//cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.css">
<script src="//cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js"></script>
</head>

<body>


      <input type="text" id="search-box" class="form-control">
<table class="table table-striped">
            <thead>
                <tr>
                    <th>Number</th>
                    <th>Name</th>
                    <th>Starts</th>
                    <th>Duration</th>
                    <th>Room</th>
                    <th><span class="glyphicon glyphicon-info-sign"></span></th>
                </tr>
            </thead>
            <tbody id="hits-container">
            </tbody>
</table>
<div id="pagination-container"></div>


<script>


var search = instantsearch({
  appId: '5V0BUFDX8J',
  apiKey: 'a25692c12853aea7a77c5a7125498512',
  indexName: 'C86FE050-6C48-11E5-84AA-BA5F164D0BA4_events',
  urlSync: true
});

search.addWidget(
instantsearch.widgets.searchBox({
  container: '#search-box',
  autofocus: true,
  placeholder: 'Search for events by keyword, description, or event number.'
})
);

search.addWidget(
    instantsearch.widgets.hits({
      container: '#hits-container',
      templates: {
        empty: 'No events found',
        item: '<tr><td><a href="{{view_uri}}">{{event_number}}</a></td><td><a href="{{view_uri}}" target="_new">{{name}}</a></td><td>{{startdaypart_name}}</td><td>{{duration_name}}</td><td>{{room_name}}</td><td><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" title="{{description}}"></span></td></tr>'
      },
    })
  );

  search.addWidget(
    instantsearch.widgets.pagination({
      container: '#pagination-container'
    })
  );

  search.start();

</script>

  </body>

</html>

1 个答案:

答案 0 :(得分:2)

好的,事实证明这是Safari和instantsearch.js之间的错误。通过改变这个:

var search = instantsearch({
  //...
  urlSync: true
});

对此:

var search = instantsearch({
  //...
  urlSync: { useHash: true }
});

错误消失了。