问题描述
我是车把的新手。在这里,我想在 javascript 文件中加载 .hbs 文件。我曾尝试使用 id="quote-template" 的内联脚本工作正常,但现在我制作了一个单独的文件。如何在 javascript 文件中链接 .hbs 文件。可以建议我。 index.html
HTML
<div id="quotedata"></div>
Handlebars
<script id="quote-template" type="text/x-handlebars-template">
<h3>Favorite {{name}} Quotes</h3>
<ol>
{{#each quotes}}
<li>{{quote}}</li>
{{/each}}
</ol>
</script>
JS
var quoteInfo = document.getElementById('quote-template').innerHTML;// this line
var template = Handlebars.compile("quoteInfo");
var quotedata = template({
name: "Tom",quotes: [
{quote: "If you don't kNow where you are going,you might wind up someplace else."}
]
});
document.getElementById('quotedata').innerHTML += quotedata;
我是这样试的
$.get('./assets/js/main.hbs',function (data) {
var template=Handlebars.compile(data);
var quoteData = template({
name: "Tom",quotes: [
{quote: "If you don't kNow where you are going,you might wind up someplace else."},]
});
$('#quotedata').html(template(quoteData));
},'html');
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)