由于未定义Handlebars,我收到错误
app/components/chart-container/chart-container.js
15 | var theTemplate = Handlebars.compile(chartContainerTemplate);
^ 'Handlebars' is 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
};
}());
在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>
我错过了什么?
答案 0 :(得分:0)
在启动模板之前等待下载所有资源
<script>
$(document).ready(function () {
// launch your function here
});
</script>