ICanHaz/Mustache.js 不渲染模板
我有一个 Mustache.js 模板,如下定义:
<script id="wishlist_template" type="text/html">
<h1>aaa{{ title }}</h1>
</script>
我尝试直接使用 Mustache,然后使用 ICanHaz.js,似乎都没有完成这项工作。如果我传入:
console.log( ich.wishlist_template('{title: "blah blah"}') );
我在控制台日志中看到的是:
<h1>aaa</h1>
我还尝试了一个真实的对象,即我试图渲染的对象(上面的代码是我试图解决问题的尝试)。
I have a mustache.js template defined like so:
<script id="wishlist_template" type="text/html">
<h1>aaa{{ title }}</h1>
</script>
I've tried to use Mustache directly, then ICanHaz.js, neither seem to be doing the job. If I pass in:
console.log( ich.wishlist_template('{title: "blah blah"}') );
All I see in the console log is:
<h1>aaa</h1>
I've also tried it with a true object, the one I'm trying to render (the above code is my attempt at figuring out the problem).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
'{title: "blah blah"}'
不是有效的对象文字,而只是一个字符串。相反,它应该是不带引号的{title: "blah blah"}
。请参阅文章JavaScript 编程语言概览,了解对象字面量的详细解释。'{title: "blah blah"}'
is not a valid object literal, but rather just a string. Instead it should be{title: "blah blah"}
without the quotes. See the article A Survey of the JavaScript Programming Language for a great explanation of object literals.删除
title
周围的空格,如下所示:{{title}}
空格在那里很重要,并且 Mustache 可能正在寻找
" title "
内部您的数据对象而不是“title”
。remove the spaces around
title
like this:{{title}}
spaces are significant there, and Mustache is probably looking for
" title "
inside of your data object instead of"title"
.