类型渲染灰尘时出错.js模板
TypeError when rendering dust.js template
我有一个dust.js模板,应该渲染一个来自mongodb集合的JSON对象。
{
"author": "Leslie Horn",
"title": "An Awesome 132-Cube Ice Tray Exists Because People Are Assholes",
"published": "2013-06-13T21:00:00.000Z",
"link": "http://gizmodo.com/an-awesome-132-cube-ice-tray-exists-because-people-are-513229668",
"feed": {
"link": {
"xml": "feed/http://feeds.gawker.com/gizmodo/excerpts.xml",
"html": "http://gizmodo.com"
},
"title": "Gizmodo"
},
"summary": "<p><img alt='"An Awesome 132-Cube Ice Tray Exists Because People Are Assholes'" height='"360'" width='"640'" src='"http://img.gawkerassets.com/img/18qq51qya5ckrpng/ku-xlarge.png'"></p> <p>First, there's a special place in hell for people who leave the ice trays empty. Ugh! But those people exist, so thankfully <a href='"http://www.lekueusa.com/product-search/Ice-Box-White-plu0250400B01C002.html'">Lékué makes a tray</a> that has space to store 132 cubes. </p><p><a href='"http://gizmodo.com/an-awesome-132-cube-ice-tray-exists-because-people-are-513229668'">Read more...</a></p><img width='"1'" height='"1'" src='"http://gizmodo.feedsportal.com/c/34976/f/647164/s/2d41b89d/mf.gif'" border='"0'"><div><table border='"0'"><tr><td valign='"middle'"><a href='"http://share.feedsportal.com/share/twitter/?u=http%3A%2F%2Fgizmodo.com%2Fan…668&t=An+Awesome+132-Cube+Ice+Tray+Exists+Because+People+Are+Assholes'"><img src='"http://res3.feedsportal.com/social/twitter.png'" border='"0'"></a> <a href='"http://share.feedsportal.com/share/facebook/?u=http%3A%2F%2Fgizmodo.com%2Fa…668&t=An+Awesome+132-Cube+Ice+Tray+Exists+Because+People+Are+Assholes'"><img src='"http://res3.feedsportal.com/social/facebook.png'" border='"0'"></a> <a href='"http://share.feedsportal.com/share/linkedin/?u=http%3A%2F%2Fgizmodo.com%2Fa…668&t=An+Awesome+132-Cube+Ice+Tray+Exists+Because+People+Are+Assholes'"><img src='"http://res3.feedsportal.com/social/linkedin.png'" border='"0'"></a> <a href='"http://share.feedsportal.com/share/gplus/?u=http%3A%2F%2Fgizmodo.com%2Fan-a…668&t=An+Awesome+132-Cube+Ice+Tray+Exists+Because+People+Are+Assholes'"><img src='"http://res3.feedsportal.com/social/googleplus.png'" border='"0'"></a> <a href='"http://share.feedsportal.com/share/email/?u=http%3A%2F%2Fgizmodo.com%2Fan-a…668&t=An+Awesome+132-Cube+Ice+Tray+Exists+Because+People+Are+Assholes'"><img src='"http://res3.feedsportal.com/social/email.png'" border='"0'"></a></td></tr></table></div><br><br><a href='"http://da.feedsportal.com/r/165665057117/u/49/f/647164/c/34976/s/2d41b89d/kg/342-363/a2.htm'"><img src='"http://da.feedsportal.com/r/165665057117/u/49/f/647164/c/34976/s/2d41b89d/kg/342-363/a2.img'" border='"0'"></a><img width='"1'" height='"1'" src='"http://pi.feedsportal.com/r/165665057117/u/49/f/647164/c/34976/s/2d41b89d/kg/342-363/a2t.img'" border='"0'"><div>'n<a href='"http://feeds.gawker.com/~ff/gizmodo/excerpts?a=iGWw_D7Zjj0:Xf9e--TXu90:yIl2AUoC8zA'"><img src='"http://feeds.feedburner.com/~ff/gizmodo/excerpts?d=yIl2AUoC8zA'" border='"0'"></a> <a href='"http://feeds.gawker.com/~ff/gizmodo/excerpts?a=iGWw_D7Zjj0:Xf9e--TXu90:qj6IDK7rITs'"><img src='"http://feeds.feedburner.com/~ff/gizmodo/excerpts?d=qj6IDK7rITs'" border='"0'"></a> <a href='"http://feeds.gawker.com/~ff/gizmodo/excerpts?a=iGWw_D7Zjj0:Xf9e--TXu90:V_sGLiPBpWU'"><img src='"http://feeds.feedburner.com/~ff/gizmodo/excerpts?i=iGWw_D7Zjj0:Xf9e--TXu90:V_sGLiPBpWU'" border='"0'"></a> <a href='"http://feeds.gawker.com/~ff/gizmodo/excerpts?a=iGWw_D7Zjj0:Xf9e--TXu90:dnMXMwOfBR0'"><img src='"http://feeds.feedburner.com/~ff/gizmodo/excerpts?d=dnMXMwOfBR0'" border='"0'"></a>'n</div><img src='"http://feeds.feedburner.com/~r/gizmodo/excerpts/~4/iGWw_D7Zjj0'" height='"1'" width='"1'">",
"_id": "528384f6ce53a99468000006",
"__v": 0
}
问题是,我在渲染对象时总是收到 TypeError。
Uncaught TypeError: Object #<h> has no method '_get'
该模板使用 grunt-dustjs 在服务器上预编译。
<article class="article">
<div class="article-feed">
<p class="published">{published}</p>
<h1><a href="{feed.link.html}" target="_blank">{feed.title|s}</a></h1>
</div>
<h2><a href="{link}" target="_blank">{title|s}</a></h2>
{?content}
<div class="article-content">{content|s}</div>
{:else}
{?summary}
<div class="article-summary">{summary|s}</div>
{/summary}
{/content}
</article>
编译后的模板如下所示
(function() {
dust.register("article", body_0);
function body_0(chk, ctx) {
return chk.write("<article class='"article'"><div class='"article-feed'"><p class='"published'">").reference(ctx._get(false, ["published"]), ctx, "h").write("</p><h1><a href='"").reference(ctx._get(false, ["feed", "link"]), ctx, "h").write("'" target='"_blank'">").reference(ctx._get(false, ["feed", "title"]), ctx, "h", ["s"]).write("</a></h1></div><h2><a href='"").reference(ctx._get(false, ["link"]), ctx, "h").write("'" target='"_blank'">").reference(ctx._get(false, ["title"]), ctx, "h", ["s"]).write("</a></h2>").exists(ctx._get(false, ["content"]), ctx, {"else": body_1,"block": body_3}, null).write("</article>");
}
function body_1(chk, ctx) {
return chk.exists(ctx._get(false, ["summary"]), ctx, {"block": body_2}, null);
}
function body_2(chk, ctx) {
return chk.write("<div class='"article-summary'">").reference(ctx._get(false, ["summary"]), ctx, "h", ["s"]).write("</div>");
}
function body_3(chk, ctx) {
return chk.write("<div class='"article-content'">").reference(ctx._get(false, ["content"]), ctx, "h", ["s"]).write("</div>");
}
return body_0;
})();
不幸的是,我在网上找不到任何解决方案。我在 mongodb 中尝试了精益查询,但也没有用。
奇怪的是它以前工作过,但是自从我更改了数据库架构以来,它就停止了工作。
您使用哪个版本的 Dust 进行渲染。看起来您正在使用 2.2.0 进行编译,但使用早期版本进行渲染。Dust 内部 API 在 2.2.0 中发生了变化(get
和 getPath
在编译的 Dust 中被替换为 _get
)。_get
方法是在 2.2.0 中添加的,因此如果您使用旧版本的 Dust 进行渲染,则会收到此错误。
相关文章:
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- Backbone.js将模型绑定到视图时出错
- 如何解决'窗口未定义'终端上的节点JS出错
- 在节点 js 中使用护照本地模块验证(登录)密码时出错
- 使用Pebble.js获取AJAX请求时出错
- Composer-view.js文件出错
- 将JS项目导入eclipse时出错
- 尝试构建 ember js 项目时出错
- 帆上的自定义和多语言消息如何出错 js.
- Node.js错误:参数太多上传批量数据时出错
- 流星js模板助手导致页面首次加载时出错
- 使用Sequelize.js创建简单PUT请求时出错
- 尝试使用Angular.js显示验证消息时出错
- 安装vertx时出错(vertx运行server.js)
- 解析从js发送到Java的json字符串时出错
- 要求JS 2.1.9引起“;最大调用堆栈"使用Grunt时出错
- 在AngularJS中实现chart.js时出错
- 类型渲染灰尘时出错.js模板
- 可以忽略“加载脚本时出错”js 错误吗?
- 转义字符串用于高亮显示函数时出错(js -regexp)