玉这个东西怎么样?

我正在学习如何构build简单的CRUD Web应用程序,并在ejs中编写指令。 但是,我刚开始学习玉,不知道如何将这个ejs代码转换为玉。

<% 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') 

所以你想知道如何用玉来写第二部分。 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。