我正在将项目从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时可以正常工作。
希望大家可以帮助我重新评估这个。
谢谢