【发布时间】:2015-09-16 23:47:00
【问题描述】:
我刚刚开始使用 Handlebars.js,我已经对 HTML 中应该包含的内容感到困惑。
我设置了一个最小的 helloworl HTML 文件,如下所示:
<html>
<body>
<script id="entry-template" type="text/x-handlebars-template">
<div class="entry">
<h1>{{title}}</h1>
<div class="body">
{{body}}
</div>
</div>
</script>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/handlebars/handlebars.js"></script>
<script src="bower_components/handlebars/handlebars.runtime.js"></script>
<script type="text/javascript">
var source = $("#entry-template").html();
var template = Handlebars.compile(source);
var context = {title: "My New Post", body: "This is my first post!"};
var html = template(context);
document.write(html);
</script>
</body>
</html>
我收到以下错误:
[Error] TypeError: undefined is not a function (evaluating 'Handlebars.compile(source)')
global code (index.html, line 17)
为了让这个最小的示例正常工作,还应该包含哪些其他依赖项?
使用的版本:
- jQuery 2.1.4
- 车把 4.0.2
【问题讨论】: