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'標籤問題。看看我的答案 –