我正在使用Algolia autocomplete(JQuery)。
它完全适用于Chrome,Firefox等,但Internet Explorer 11
在IE上,它会导致SCRIPT1010:预期标识符错误,来自带有函数footerTemplate的行
我不知道该怎么做;任何建议将不胜感激。感谢
以下是我的代码摘录:
var client = algoliasearch('{{ getenv('ALGOLIA_APP_ID') }}', '{{ getenv('ALGOLIA_PUBLIC') }}');
var index_classes = client.initIndex('classes');
var index_stories = client.initIndex('articles');
jQuery(function($) {
var client = algoliasearch('{{ getenv('ALGOLIA_APP_ID') }}', '{{ getenv('ALGOLIA_PUBLIC') }}');
var index_classes = client.initIndex('classes');
var index_stories = client.initIndex('articles');
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
nr_res = 3;
nr_res_2 = 1;
} else {
nr_res = 5;
nr_res_2 = 5;
}
$('input[name="search_text"]').autocomplete(
{ debug:true,
templates: {
footer: '<div id="see-all-sr"><hr><a href="#" style="size:16px;padding-left:12px;color:blue;text-decoration:underline">See all results in detail</a><br> </div>'
}
}, [
{
source: $.fn.autocomplete.sources.hits(index_classes, { hitsPerPage: nr_res }),
displayKey: 'name',
name: 'class',
templates: {
header: '<div class="aa-suggestions-category">Classes (top ' + nr_res + ')</div>',
suggestion: function(suggestion) {
return '<img src="/images/class/' + suggestion.id + '_100.jpg">' + '<div><span>' +
suggestion._highlightResult.name.value + '</span><span>'
+ suggestion._highlightResult.teacher_name.value + '</span>';
},
empty: '<div class="aa-empty">No results. See <a style="color:blue;text-decoration:underline" href="/classes">all classes</a></div>',
footer: function footerTemplate({ query, isEmpty }) {
if (!isEmpty) {
$('#see-all-sr').show();
}
}
}
},
{
source: $.fn.autocomplete.sources.hits(index_stories, { hitsPerPage: nr_res_2 }),
displayKey: 'title',
name: 'story',
templates: {
header: '<div class="aa-suggestions-category">Stories (top ' + nr_res_2 + ')</div>',
suggestion: function(suggestion) {
return '<img src="/images/article/' + suggestion.id + '_100.jpg">' + '<div><span>' +
suggestion._highlightResult.title.value + '</span><span>' +
suggestion._highlightResult.author_name.value + '</span></div>';
},
empty: '<div class="aa-empty">No results. See <a style="color:blue;text-decoration:underline" href="/stories">all stories</a></div>',
footer: function footerTemplate({ query, isEmpty }) {
if (!isEmpty) {
$('#see-all-sr').show();
}
}
}
}
]).on('autocomplete:selected', function(event, suggestion, dataset) { // https://github.com/algolia/autocomplete.js#jquery
window.location = '/' + suggestion.url;
}).on('autocomplete:empty', function() {
$('#see-all-sr').hide();
});
});
答案 0 :(得分:0)
函数定义使用IE11不支持的ES6语法。
用以下代码替换函数定义:
footer: function footerTemplate(obj) {
if (!obj.isEmpty) {
$('#see-all-sr').show();
}
}