每个记录使用node-json2html给出单独的html表

时间:2017-01-18 09:02:10

标签: javascript node.js json2html

我正在使用json数据创建html表,我的转换为每个记录提供了一个单独的表。

 var data=[{"name":"aa","mid":"12345","user":"a123","password":"a@123"},{"name":"bb","mid":"2345","user":"b123","password":"b@123"}]
var transform=[
    {"<>":"style","html":"table,th,td {border: 1px solid black;border-collapse: collapse;}th {text-align: left;}"},
    {"<>":"p","html":"Dear client"},
    {"<>":"p","html":"Please find below merchant users passwords are expired. Kindly take necessaray action immediately."},
    {"<>":"table","style":"width:100%","html":[
        {"<>":"tbody","html":[
            {"<>":"tr","html":[
                {"<>":"th","id":"name","html":"Client Name"},
                {"<>":"th","id":"mid","html":"MID Number"},
                {"<>":"th","id":"username","html":"Username"},
                {"<>":"th","id":"password","html":"Current Password"}
            ]},
        {"<>":"tbody","id":"json-body","html":[
            {"<>":"tr","html":[
                {"<>":"td","html":"${name}"},
                {"<>":"td","html":"${mid}"},
                {"<>":"td","html":"${user}"},
                {"<>":"td","html":"${password}"}
            ]},
        ]},
        ]},
    ]},
    {"<>":"p","html":"Thanks & Regards"},
    {"<>":"p","html":"support@aa.com"}
]

如何通过将所有数据放入单个html表中来实现此目的?

1 个答案:

答案 0 :(得分:1)

您可以将数据更改为具有键Object的{​​{1}},然后定义新的users和新的内联函数以转换transform

ps:我认为第一个data.users应为tbody

代码如下:

thead

this enter image description here