我的模板带有 Handlebars ,并且工作时间最长,但有时会出现此错误无法调用未定义的“匹配”方法。这是我的代码
查看
<div id="template"></div>
<script id="template-script" type="text/x-handlebars-template">
{{#measures_list}}
<div class="col-lg-7 col-lg-offset-1">
<p class="indicator-title gray-bottom-border">{{name}}</br></p>
<div>
<p><span class="font30px">{{total}} </span> Total {{name}}<br><span class="green-text">{{increase}}%</span> from last <span class="metric_time"></span></p>
</div>
<div class="graph-header">
<h3>{{this_interval}} </h3><p>New {{name}}</p>
<p class="percentage-graph green-text">{{percentage}}%<p>
</div>
<div id={{graph_id}} class="graph"></div>
</div>
{{/measures_list}}
</script>
js
var source=$("#template-script").html();
var template=Handlebars.compile(source);
$('#template').empty().append(template(template_data));
console.log('source'+source+'template'+template)
我使用console.log来查看错误,很多时候工作正常,但在某些情况下源未定义,页面出现多次,例如我单击一个按钮,并在关闭页面并单击后出现再次按下按钮并执行多次,多次后或第一次后给我错误:无法调用未定义的方法“匹配”
请帮忙
最佳答案
var source=$("#template-script").html() || '';
关于javascript - 无法调用未定义 Handlebars 问题的方法 'match',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21317942/