Question

I have a dust.js template that should render a JSON object coming from a mongodb collection.

{
  "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
}

The problem is, that I'm always getting a TypeError when rendering the object.

Uncaught TypeError: Object #<h> has no method '_get' 

The template is precompiled on the server using 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>

The compiled template looks like this

(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;
})();

unfortunately I couldn't find any solution on the web. I tried lean queries in mongodb, which didn't work also.

The strange thing is that it worked before, but since I changed my database schema it just stopped working.

Was it helpful?

Solution

What version of Dust are you using for rendering. It looks like you are using 2.2.0 for compiling, but using an earlier version for rendering. The Dust internal API changed with 2.2.0 (get and getPath were replaced with _get in compiled Dust). The _get method was added in 2.2.0, so if you are using an older version of Dust to render, you will get this error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top