如何将嵌套EJS forEach循环转换为HBS #each循环?
EJS嵌套循环转Handlebars实现
以下是将你的嵌套EJS forEach 循环转换为Handlebars #each 循环的完整代码:
{{#each projeler as |projeDizisi|}} {{#each projeDizisi as |proje|}} <div id="reg-modal{{proje.id}}" class="modal fade" tabindex="-1"> <div class="modal-dialog modal-xl"> <div class="modal-content d-flex"> <div class="modal-header text-center"> <h5 class="modal-title w-100 display-1"> {{proje.proje_ismi}} </h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> <div class="project_details_wrapper"> <h4 class="text-center fs-3 mb-4">Proje Detayları</h4> <table class="table table-dark table-striped"> <tbody> <tr> <th>İsim</th> <td>{{proje.isim}}</td> </tr> <tr> <th>Soy İsim</th> <td>{{proje.soyisim}}</td> </tr> <tr> <th>Şirket</th> <td>{{proje.sirket}}</td> </tr> <tr> <th>Departman</th> <td>{{proje.departman}}</td> </tr> <tr> <th>Kategori</th> <td>{{proje.proje_kategorisi}}</td> </tr> <tr> <th>Proje Açıklaması</th> <td>{{proje.proje_aciklamasi}}</td> </tr> <tr> <th>Proje Eklenme Tarihi</th> <td>{{proje.proje_eklenme_tarihi}}</td> </tr> </tbody> </table> <img class="img-fluid" src="../images/randomForLibrary/{{proje.proje_resmi_url}}"> <p class="mt-3">{{proje.proje_aciklaması}}</p> <div class="mt-5"> <h3>Proje Dosyaları</h3> <a href="./user_files/{{proje.proje_dosyalari_url}}" download> Projeye ait dosyaları indirin <!-- <input type="button" class="btn--green" value="Download"> --> </a> </div> </div> </div> </div> </div> </div> {{/each}} {{/each}}
关键转换点:
- 用Handlebars的
{{#each 数组 as |别名|}}语法替代EJS的forEach循环,嵌套循环需对应使用{{/each}}闭合标签 - 变量输出从EJS的
<%= 变量 %>改为Handlebars的{{变量}}语法 - 模态框ID等拼接内容直接在双大括号中完成变量插入
内容的提问来源于stack exchange,提问作者Tolkienist Coder
相关产品推荐
相关产品推荐

