gpt4 book ai didi

javascript - 渲染 dust.js 模板时出现 TypeError

转载 作者:可可西里 更新时间:2023-11-01 09:45:05 25 4
gpt4 key购买 nike

我有一个 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&amp;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&amp;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&amp;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&amp;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&amp;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 中发生了变化(getgetPath 在已编译的 Dust 中被替换为 _get)。 _get 方法是在 2.2.0 中添加的,因此如果您使用旧版本的 Dust 进行渲染,则会出现此错误。

关于javascript - 渲染 dust.js 模板时出现 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19964772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com