使用 Handlebar.js

2023-12-31

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

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

我正在做的是我有一个索引.html file,

<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>

and an 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)); 

但我得到的只是一张空白页。我在这里犯了什么错误吗?详细的解释会很有帮助。


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

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

在这里摆弄 http://jsfiddle.net/3U4uh/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Handlebar.js 的相关文章

随机推荐