こちらに次のループで管理ページを追加したいのですがうまくできなくて。アドバイスいただければ幸いです。
index.ejs
{ "default": { "title": "タイトル", "description": "", "category": "default", "target": "user", "header": "", "footer": "", "sidebar": "", "parent": "", "note": "" }, "user_top": { "title": "TOP", "category": "top", "target": "user", "header": "user-header", "footer": "user-footer", "parent": "none" }, "login": { "title": "ログイン", "description": "", "category": "login", "target": "user", "header": "login", "footer": "", "sidebar": "", "parent": "" }, "admin": { "title": "管理ページ", "description": "", "category": "admin", "target": "user", "header": "admin", "footer": "", "sidebar": "", "parent": "" } } var categories = { top: "TOP", login: "ログイン", admin: "管理ページ" }, current_cat, counter = 1
<main class="container"> <div class="starter-template py-5 px-3" style="margin-top: 4em"> <h1>画面一覧</h1> <p class="lead"></p> <%# JSON.stringify(json) %> <div class="mt-5"> <% Object.keys(json).forEach(function (key, index) { %> <% if (key === 'default') { return; } %> <% if(json[key]['category'] !== current_cat) { %> <% if(current_cat) { %> </tbody> </table> </div> <div class="mt-5"> <% } %> <h2 class="h3"><%= categories[json[key]['category']] %></h2> <table class="table table-striped table-hover"> <thead> <tr> <th scope="col" style="width: 2em"><span style="font-size: .9em">No</span></th> <th scope="col" style="width: 35%"><span style="font-size: .9em">画面名</span></th> <td scope="col" style="width: 30%"><span style="font-size: .9em">ファイル名</span></td> <td scope="col"><span style="font-size: .9em">補足 </span></td> </tr> </thead> <tbody> <% } %> <tr> <th><%= counter++ %></th> <th><%= json[key]['description'] ? json[key]['description'] : json[key]['title'] %></th> <td><a href="<%= key %>.html" target="_blank"><%= key %>.html</a></td> <td style="font-size: .9em"><%= json[key]['note'] %></td> </tr> <% current_cat = json[key]['category'] %> <% }); %> </tbody> </table> </div> </div> </main><!-- /.container -->
出力結果
<h1>一覧</h1> <p class="lead"></p> <div class="mt-5"> <h2 class="h3">TOP</h2> <table class="table table-striped table-hover"> <thead> <tr> <th scope="col" style="width: 2em"><span style="font-size: .9em">No</span></th> <th scope="col" style="width: 35%"><span style="font-size: .9em">画面名</span></th> <td scope="col" style="width: 30%"><span style="font-size: .9em">ファイル名</span></td> <td scope="col"><span style="font-size: .9em">補足 </span></td> </tr> </thead> <tbody> <tr> <th>1</th> <th>TOP</th> <td><a href="user_top.html" target="_blank">user_top.html</a></td> <td style="font-size: .9em"></td> </tr> </tbody> </table> </div> <div class="mt-5"> <h2 class="h3">ログイン</h2> <table class="table table-striped table-hover"> <thead> <tr> <th scope="col" style="width: 2em"><span style="font-size: .9em">No</span></th> <th scope="col" style="width: 35%"><span style="font-size: .9em">画面名</span></th> <td scope="col" style="width: 30%"><span style="font-size: .9em">ファイル名</span></td> <td scope="col"><span style="font-size: .9em">補足 </span></td> </tr> </thead> <tbody> <tr> <th>2</th> <th>ログイン</th> <td><a href="login.html" target="_blank">login.html</a></td> <td style="font-size: .9em"></td> </tr> </tbody> </table> </div>
あなたの回答
tips
プレビュー