0
我是一个非常新的学习者的把手和Javascript,所以我提前道歉。作为学习Handlebars的一种方式,我正在尝试将来自在线示例的所有基本组件放入一个独立的网页中。然而它运行不好。把手:无法编译?
<html>
<head>
<script type="text/javascript" src="scripts/jquery-3.1.1.min.js" />
<script type="text/javascript" src="scripts/handlebars-v4.0.5.js" />
</head>
<body>
<div id="content-placeholder"></div>
<script id="some-template" type="text/x-handlebars-template">
<table>
<thead>
<th>Username</th>
<th>Real Name</th>
<th>Email</th>
</thead>
<tbody>
{{#users}}
<tr>
<td>{{username}}</td>
<td>{{firstName}} {{lastName}}</td>
<td>{{email}}</td>
</tr>
{{/users}}
</tbody>
</table>
</script>
<script>
var source = $("#some-template").html();
alert(source);
var template = Handlebars.compile(source);
var data = { users: [
{username: "alan", firstName: "Alan", lastName: "Johnson", email: "[email protected]" },
{username: "allison", firstName: "Allison", lastName: "House", email: "[email protected]" },
{username: "ryan", firstName: "Ryan", lastName: "Carson", email: "[email protected]" }
]};
$("#content-placeholder").html(template(data));
</script>
</body>
</html>
此外,我无法打印源(警报(源)显示“未定义”)。有什么缺失?谢谢您的帮助!
您没有正确,因此关闭了'script'标签问题。看看我的答案 –