使用Handlebar.js

use*_*973 6 javascript handlebars.js

我实际上是想在Handlebar.js上找到一些教程,我发现了这个http://javascriptplayground.com/blog/2012/05/javascript-templating-handlebars-tutorial

但它实际上并没有按预期工作.

我正在做的是我有一个index.html文件,

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js" type="text/javascript" charset="utf-8"></script>
        <script src="app.js" type="text/javascript" charset="utf-8"></script>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Messing with Handlebars</title>

    </head>
    <body>
        <script id="ajax-comment" type="text/x-handlebars-template">
            <li>
            <span class="meta">{{name}} on {{date}}</span>
            <p>{{comment}}</p>
            </li>
        </script>

    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

以及包含代码的app.js.

var source = $("#ajax-comment").html();
var template = Handlebars.compile(source);
var data = {
    name : "Jack",
    date : "12/04/12",
    comment : "This is a really awesome tutorial. Thanks."
};
$("ul").append(template(data)); 
Run Code Online (Sandbox Code Playgroud)

但我得到的只是一个空白页面.我在这里犯的任何错误?详细解释会有所帮助.

Aus*_*eco 3

"ul"元素不存在,您必须将其附加到实际存在的元素上。

<ul></ul>只需在身体某处添加一个即可。

在这里摆弄