我正在学习如何构建简单的 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 文档的链接:Jade Iterations.
关于node.js - 这个 ejs 在 jade 中会是什么样子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36522817/