問題:尋找Jquery或javascript解決方案,使用下面的JSON結構創建帶有colspan的動態錶行。我面臨的問題是創建 所需的行。我嘗試過很多場景,但無法找到TR來追加TH。使用JSON動態創建HTML表格行
非常感謝您的幫助。
這裏是我的JSON格式
[{"data":"test","nodes":[{"data":"5.00%","nodes":[{"data":"5.00%","nodes":[{"data":"Jul 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Aug 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Sep 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Oct 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Nov 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Dec 2014","nodes":[{"data":"Result","nodes":null}]}]},{"data":"70.00%","nodes":[{"data":"Jul 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Aug 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Sep 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Oct 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Nov 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Dec 2014","nodes":[{"data":"Result","nodes":null}]}]},{"data":"80.00%","nodes":[{"data":"Jul 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Aug 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Sep 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Oct 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Nov 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Dec 2014","nodes":[{"data":"Result","nodes":null}]}]}]},{"data":"5.00%","nodes":[{"data":"5.00%","nodes":[{"data":"Jul 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Aug 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Sep 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Oct 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Nov 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Dec 2014","nodes":[{"data":"Result","nodes":null}]}]},{"data":"70.00%","nodes":[{"data":"Jul 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Aug 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Sep 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Oct 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Nov 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Dec 2014","nodes":[{"data":"Result","nodes":null}]}]},{"data":"80.00%","nodes":[{"data":"Jul 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Aug 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Sep 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Oct 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Nov 2014","nodes":[{"data":"Result","nodes":null}]},{"data":"Dec 2014","nodes":[{"data":"Result","nodes":null}]}]}]}]}]
這裏是我想實現
HTML結構
<table>
<tr>
<th colspan="36">test</th>
</tr>
<tr>
<td colspan="18">5.00%</td>
<td colspan="18">5.00%</td>
</tr>
<tr>
<td colspan="6">5.00%</td>
<td colspan="6">70.00%</td>
<td colspan="6">80.00%</td>
<td colspan="6">5.00%</td>
<td colspan="6">70.00%</td>
<td colspan="6">80.00%</td>
</tr>
<tr>
<td colspan="1">Jul 2014</td>
<td colspan="1">Aug 2014</td>
<td colspan="1">Sep 2014</td>
<td colspan="1">Oct 2014</td>
<td colspan="1">Nov 2014</td>
<td colspan="1">Dec 2014</td>
<td colspan="1">Jul 2014</td>
<td colspan="1">Aug 2014</td>
<td colspan="1">Sep 2014</td>
<td colspan="1">Oct 2014</td>
<td colspan="1">Nov 2014</td>
<td colspan="1">Dec 2014</td>
<td colspan="1">Jul 2014</td>
<td colspan="1">Aug 2014</td>
<td colspan="1">Sep 2014</td>
<td colspan="1">Oct 2014</td>
<td colspan="1">Nov 2014</td>
<td colspan="1">Dec 2014</td>
<td colspan="1">Jul 2014</td>
<td colspan="1">Aug 2014</td>
<td colspan="1">Sep 2014</td>
<td colspan="1">Oct 2014</td>
<td colspan="1">Nov 2014</td>
<td colspan="1">Dec 2014</td>
<td colspan="1">Jul 2014</td>
<td colspan="1">Aug 2014</td>
<td colspan="1">Sep 2014</td>
<td colspan="1">Oct 2014</td>
<td colspan="1">Nov 2014</td>
<td colspan="1">Dec 2014</td>
<td colspan="1">Jul 2014</td>
<td colspan="1">Aug 2014</td>
<td colspan="1">Sep 2014</td>
<td colspan="1">Oct 2014</td>
<td colspan="1">Nov 2014</td>
<td colspan="1">Dec 2014</td>
</tr>
</table>
你有代碼,用於接收JSON?你正在尋找的功能只是爲了直接使用JSON並立即創建表格?你試過什麼了? –
是的,請直接拿JSON來創建表格。我已經嘗試了使用DFS和BFS的2-3場景,但是我沒有找到TR來追加TH。 – vinod