You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将嵌套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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 12:21:00