Шаблон пыли для вложенных математических условий

Я хочу вывести HTML-таблицу с 4 записями для каждой строки, используя шаблоны пыли.

вот шаблон:

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

и данные:

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

К сожалению, шаблон не возвращает ничего, кроме тегов таблицы.

что мне здесь не хватает?

Математический тег неправильный?

1 ответ

Решение

Ваш код в порядке. Проблема в том, что вы должны явно требовать dustjs-helpers, Я считаю, что это должно быть правильно упомянуто в документации.

  1. Вам необходимо установить dustjs-helpers

    npm install dustjs-helpers
    
  2. В коде вам нужна эта строка

    require("dustjs-helpers");
    

После выполнения этих шагов я получил сгенерированный HTML.

РЕДАКТИРОВАТЬ Поднял проблему в репо linkedin dustjs https://github.com/linkedin/dustjs/issues/339

Другие вопросы по тегам