0

I want to output html table with 4 entries for each row using dust templates.

here is the template :

var compiledtlist = dust.compile(
            "<table class='table'>" +
            "{#data}" +
            "{@math key=\"{tagid}\" method=\"mod\" operand=\"4\"}" +
            "{@eq value=0}" +
            "<tr><td><button class='btn btn-mini btn-info tag'>{tname}</button>&nbsp;x&nbsp; <span class='badge badge-info'>10</span> <br /><p>{tdesc}</p></td>" +
            "{/eq}" +
            "{@eq value=3}" +
            "<td><button class='btn btn-mini btn-info tag'>{tname}</button>&nbsp;x&nbsp; <span class='badge badge-info'>10</span> <br /><p>{tdesc}</p></td></tr>" +
            "{/eq}" +
            "{@default}" +
            "<td><button class='btn btn-mini btn-info tag'>{tname}</button>&nbsp;x&nbsp; <span class='badge badge-info'>10</span> <br /><p>{tdesc}</p></td>" +
            "{/default}" +
            "{/math}" +
            "{/data}" +
            "</table>"
            , "taglist");
            console.log(compiledtlist);
            dust.loadSource(compiledtlist);
            dust.render("taglist", { data: data }, function (err, out) {
                console.log(err);
                console.log(out);
                $('#tagstable').html(out);
            });

and the data is :

[
   {
      "tagid":10,
      "tname":"sql server",
      "tdesc":"As a database, it is a software product whose primary function is to store and retrieve data as requested by other software applications, be it those on the same computer or those running on another computer across a network (including the Internet)."
   },
   {
      "tagid":9,
      "tname":"entity framework",
      "tdesc":"ADO.NET Entity Framework (EF) is an open source[1] object-relational mapping (ORM) framework for the NET Framework"
   },
   {
      "tagid":8,
      "tname":"spring",
      "tdesc":"he Spring Framework is an open source application framework and inversion of control container for the Java platform"
   },
   {
      "tagid":7,
      "tname":"struts",
      "tdesc":"Apache Struts is an open-source web application framework for developing Java EE web applications. It uses and extends the Java Servlet API to encourage developers to adopt a model–view–controller (MVC) architecture."
   },
   {
      "tagid":6,
      "tname":"asp.net mvc",
      "tdesc":"The ASP.NET MVC Framework is an open source web application framework that implements the model–view–controller (MVC) pattern."
   },
   {
      "tagid":5,
      "tname":"asp.net",
      "tdesc":"ASP.NET is a server-side Web application framework designed for Web development to produce dynamic Web pages. It was developed by Microsoft to allow programmers to build dynamic web sites, web applications and web services."
   },
   {
      "tagid":4,
      "tname":"xml",
      "tdesc":"Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable"
   },
   {
      "tagid":3,
      "tname":"javascript",
      "tdesc":"JavaScript (JS) is an interpreted computer programming language.[5] As part of web browsers, implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed"
   },
   {
      "tagid":2,
      "tname":"java",
      "tdesc":"Java is a general-purpose, concurrent, class-based, object-oriented computer programming language that is specifically designed to have as few implementation dependencies as possible."
   },
   {
      "tagid":1,
      "tname":"c#",
      "tdesc":"C#[note 1] (pronounced see sharp) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, procedural, generic, object-oriented (class-based), and component-oriented programming disciplines"
   }
]

Unfortunately nothing is returned by the template except table tags.

what am i missing here ?

Is the math tag wrong ?

4

1 回答 1

0

您的代码非常好。问题是,您必须明确要求dustjs-helpers. 我相信这应该在文档中正确提及。

  1. 你需要安装dustjs-helpers

    npm install dustjs-helpers
    
  2. 在代码中,您需要这一行

    require("dustjs-helpers");
    

完成这些步骤后,我得到了生成的 HTML。

编辑在linkedindustjs的回购https://github.com/linkedin/dustjs/issues/339中提出了一个问题

于 2013-09-16T12:21:58.807 回答