gpt4 book ai didi

javascript - Algolia 自动完成 - 函数 footerTemplate 导致 SCRIPT1010 : Expected Identifier error

转载 作者:行者123 更新时间:2023-11-28 04:45:19 24 4
gpt4 key购买 nike

我正在使用 Algolia 自动完成 (JQuery)。

它在 Chrome、Firefox 等浏览器上完美运行,但在 Internet Explorer 11 上运行

在 IE 上,它会导致 SCRIPT1010: Expected Identifier error, from the line with function 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>&nbsp</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();
});

});

最佳答案

函数定义使用ES6语法,I​​E11不支持。

将函数定义替换为:

footer: function footerTemplate(obj) {
if (!obj.isEmpty) {
$('#see-all-sr').show();
}
}

关于javascript - Algolia 自动完成 - 函数 footerTemplate 导致 SCRIPT1010 : Expected Identifier error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43436076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com