相关疑难解决方法(0)

使用Handlebar.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)

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

javascript handlebars.js

6
推荐指数
1
解决办法
3062
查看次数

标签 统计

handlebars.js ×1

javascript ×1