//sample.json
JSON
1[
2{"classNum":"C","className":"c"},
3{"classNum":"D","className":"d"}
4]
//sample.htm
javascript
1<script>
2window.addEventListener('DOMContentLoaded', async()=>{
3 let data=[];
4 data=await fetch("sample.json").then(res=>res.json()); //JSONを呼ばないときはこの行をコメントアウト
5 if(data){
6 const t=document.querySelector('#t1 tbody');
7 const tr0=t.querySelector('tr');
8 tr0.remove();
9 data.forEach(x=>{
10 const tr1=tr0.cloneNode(true);
11 t.appendChild(tr1);
12 tr1.querySelector('td').textContent=x.classNum;
13 tr1.querySelector('td:nth-child(2)').textContent=x.className;
14 });
15 }
16});
17</script>
18<table id="t1" border>
19<thead>
20<tr><th>リスト選択</th><th>リスト名</th><th>追加/削除</th></tr>
21</thead>
22<tbody>
23<tr><td>A</td><td>a</td><td>+ -</td></tr>
24</tbody>
25</table>