我想使用 json2html 向父级添加多个子级。
jsonTestSuiteTemplate={
"testSuiteNames": [{"testSuiteName": "TS1"}],
};
var testSuiteHtmlTemplate = {
"tag": "table",
"border":"0",
"children": [{"tag": "tr",
"children": [{
"tag": "td",
"children": [{
"tag": "ul",
"class": "report",
"children":[{
"tag":"LI",
"nowrap":"false",
"class":"closed",
"children":
[{
"tag":"a",
"href":"#testsuite",
"onclick":function(){ return toggle(this);},
"children":[{
"tag":"big",
"children":[{
"tag":"font",
"color":"green",
'html':"ts1 - TS (ok)"}
}] //End of font tag
}] //End of big tag
}], //End of Anchor Tag
{
"children":[{
"tag":"LI",
"nowrap":"false",
"class":"closed",
"children":
[{
"tag":"a",
"href":"#testsuite",
"onclick":function(){ return toggle(this);},
"children":[{
"tag":"big",
"children":[{
"tag":"font",
"color":"green",
'html':"t1 - TC (ok)"}
}] //End of font tag
}] //End of big tag
}]
}] //End of inner List
}
}] // End of Link tag
}] //End of UI tag
}] // End of TD tag
}] // End of TR tag
};
var result = json2html.transform(jsonTestSuiteTemplate, testSuiteHtmlTemplate);
JSON2Html 库提供的 HTML
<table border="0"><tr><td><ul class="report"><LI nowrap="false" class="closed"><LI nowrap="false" class="closed"><a href="#testsuite"><big><font color="green">TS1</font></big></a></LI></LI></ul></td></tr></table>
但我想要这样的 HTML:
<table border="0">
<tr>
<td>
<ul class="report">
<LI nowrap="true" class="closed">
<A HREF="#testsuite" onclick="toggle(this)"><big><font color="green">ts1 - TS (ok)</font></big></A> - 0:00:03.800
<ul>
<LI nowrap="true" class="closed">
<A HREF="#testcase" onclick="toggle(this)"><big><font color="green">t1 - TC (ok)</font></big></A> - 0:00:03.800
</LI>
</ul>
</LI>
</ul>
</td>
</tr>
</table>
</td>
</tr>
</table>
我是 json2Html 库的新手,发现很难将多个孩子添加到同一个父级。非常感谢任何帮助!