简体   繁体   English

车把错误:未定义“车把”

[英]Handlebars error: 'Handlebars' is not defined

I am getting an error as Handlebars is not defined 由于没有定义车把,因此出现错误

   app/components/chart-container/chart-container.js
     15 |        var theTemplate = Handlebars.compile(chartContainerTemplate);
                                   ^ 'Handlebars' is not defined.

this is the whole file where handlebars is suppose to be not defined 这是假定未定义把手的整个文件

'use strict';

var APP = window.APP = window.APP || {};

APP.chartContainer = (function () {

    var bindEventsToUI = function () {

        $.getJSON('maindata.json', function(data) {
            var setData = localStorage.setItem('jsonData', JSON.stringify(data));
            // console.log('data', localStorage.getItem('jsonData'));
        });

        var chartContainerTemplate = $(".chart-container").html();
        var theTemplate = Handlebars.compile(chartContainerTemplate);

        var getData = localStorage.getItem('jsonData');

        var theCompiledHtml = theTemplate(getData);

        console.log(theTemplate);

        $(document.body).append(theCompiledHtml);
    };

    var init = function (element) {
        console.log('APP.chartContainer');
        bindEventsToUI();
    };

    /**
     * interfaces to public functions
     */
    return {
        init: init
    };

}());

and in the default.hbs I have this within the body tag 在default.hbs中,我在body标签内

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
 <script>window.jQuery || document.write('<script src="assets/scripts/vendor/jquery-1.11.3.min.js"><\/script>')</script>
 <script src="https://cdn.jsdelivr.net/handlebarsjs/4.0.5/handlebars.min.js"></script>

what am I missing ? 我想念什么?

Wait for the download of all the resources before launching your template 启动模板之前,请等待所有资源的下载。

<script>
    $(document).ready(function () {
        // launch your function here
    });
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM