帮助把手打印HTML标签

时间:2016-03-24 06:08:04

标签: node.js html-table handlebars.js helper

我有这个试图动态创建此表的手柄代码

<tr>
    {{#each this}}
        {{#ifCond this }}
        {{/ifCond}}
    {{/each}}
</tr>

现在我有一个像这样定义的把手帮助器(在res.render中发送这个帮助器就像这样)

'ifCond': function( state ) {
    if(state == "success") 
        return Spacebars.SafeString('<td class="tile-green">' + state + '</td>');
    else if( state == "failure")
        return Spacebars.SafeString('<td class="tile-red">' + state + '</td>');
    else if (state == "unknown"
        return Spacebars.SafeString('<td class="tile-orange">' + state + '</td>');

    else 
        return Spacebars.SafeString('<td>' + state + '</td>');
}

似乎没有效果。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

以下是如何执行此操作的示例:https://jsfiddle.net/ChristopheThiry/L34f7rm2/

模板:

{ "lines" : [
   { "columns" : [ { "state" : "STEP1" }, { "state" : "STEP2" }, { "state" : "STEP3" } ] },
   { "columns" : [ { "state" : "success" }, { "state" : "failure" }, { "state" : "unknown" } ] },
   { "columns" : [ { "state" : "success" }, { "state" : "success" }, { "state" : "unknown" } ] } 
           ] }

帮助者:

{{1}}

数据:

{{1}}