【问题标题】:Typeahead is not working in AEM 6.1 but working in CQ 5.6.1Typeahead 在 AEM 6.1 中不起作用,但在 CQ 5.6.1 中起作用
【发布时间】:2015-10-07 09:19:29
【问题描述】:

我正在将项目从 CQ 5.6.1 迁移到 AEM 6.1。

然后当我测试它时,发现我的代码中使用 typeahead.bundle.js 的部分不再工作了。当我返回在 CQ 5.6.1 中测试项目时,它运行良好。

试图隔离问题(获取代码的 sn-p 而不将其部署到 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":"افغانستان","englishName":"阿富汗"},{"url":"http://xxxx.com","localName":"Shqipëria" ,"englishName":"Albania"},{"url":"http://xxxx.com","localName":"الجزائر","englishName":"Algeria"}]

注意:请注意,上面的 HTML 脚本在未部署到 AEM 6.1 时可以正常工作。

希望大家能帮我重新评分。

谢谢

【问题讨论】:

    标签: javascript jquery java-8 aem


    【解决方案1】:

    我已经找到答案了。

    由于未声明的变量,aem6 服务器中似乎有一个未初始化的内部 javascript(很奇怪,因为它在 CQ 5.6.1 中有效)。

    所以我明确地标记了变量,它现在工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-20
      • 2018-03-03
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多