我正在將項目從CQ 5.6.1遷移到AEM 6.1。Typeahead在AEM 6.1中不工作,但在CQ 5.6.1中工作
然後,當我測試它時,發現我的代碼使用typeahead.bundle.js的部分不再工作了。當我重新測試CQ 5.6.1中的項目時,它確實工作正常。
試圖隔離問題(獲取代碼的片段W/O將其壓縮到AEM 6.1),它工作正常。
我最初的發現是單獨使用AEM 6.1服務器可能會導致typeahead.bundle.js不起作用。
<html>
<head>
<script src="jquery-2.0.0.min.js"></script>
<script src="hogan-3.0.1.js"></script>
<script src="typeahead.bundle.js"></script>
</head>
<body>
<row>
<input id="country-search" type="text" class="typeahead form-control" placeholder="Country" title="Enter the terms you wish to search for" />
</row>
<script type="text/javascript">
$(document).ready(function() {
var countries = new Bloodhound({
name: 'countrysearch-countries',
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('englishName', 'localName'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 5,
prefetch: {
url: 'country.json',
}
});
var countrySuggestionTemplate = Hogan.compile('<p>{{localName}} ({{englishName}})</p>');
countries.initialize();
$("#country-search").typeahead(null, {
displayKey: 'localName',
source: countries.ttAdapter(),
templates: {
suggestion: function(country) {
return countrySuggestionTemplate.render(country);
}
}
}).on('typeahead:selected', function (e, datum) {
window.location = datum.url;
});
});
</script>
country.json的
JSON字符串內容:
[{ 「URL」: 「http://xxxx.com」, 「的localName」: 「افغانستان」, 「中文名」: 「阿富汗」},{ 「URL」 :「http://xxxx.com」,「localName」:「Shqipëria」,「englishName」:「Albania」},{「url」:「http://xxxx.com」,「localName」:「الجزائر」,「englishName」:「阿爾及利亞」}]
注意:請注意,上面的HTML腳本在未部署到AEM 6.1時可以正常工作。
希望大家可以幫助我重新評估這個。
謝謝