这个 ejs 在 jade 中看起来像什么?

what can this ejs be look like in jade?

我正在学习如何构建简单的 CRUD Web 应用程序,说明是用 ejs 编写的。但是,我刚开始学习jade,不知道如何将这个ejs代码转换成jade。

<% layout( 'layout' ) -%>

<h1 id="page-title"><%= title %></h1>

<div id="list">
  <form action="/create" method="post" accept-charset="utf-8">
    <div class="item-new">
      <input class="input" type="text" name="content" />
    </div>
  </form>

<% todos.forEach( function ( todo ){ %>
  <div class="item">
    <a class="update-link" href="/edit/<%= todo._id %>" title="Update this todo item"><%= todo.content %></a>
    <a class="del-btn" href="/destroy/<%= todo._id %>" title="Delete this todo item">Delete</a>
  </div>
<% }); %>
</div>

这就是我所做的,

extends layout

h1#page-title= title
#list
  form(action="/create" method="post" accept-charset='utf-8')
    .item-new
      input(type='text' name='content')

所以你想知道如何用 jade 编写第二部分。 Each 是 Jades 主要的迭代方法之一。你的代码可以这样写:

each todo in todos
  .item
    a(class="update-link" href="/edit/"+todo._id title="Update this todo item")= todo.content
    a(class="del-btn" href="/destroy/"+todo._id title="Delete this todo item") Delete

这里是关于迭代的 jades 文档的link:Jade Iterations.