【问题标题】:what can this ejs be look like in jade?这个ejs在jade中会是什么样子?
【发布时间】:2016-04-09 21:17:06
【问题描述】:

我正在学习如何构建简单的 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')

【问题讨论】:

    标签: node.js pug ejs


    【解决方案1】:

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

    这里是关于迭代的翡翠文档链接:Jade Iterations.

    【讨论】:

    • 我检查了文件。我更有可能通过示例更好地理解。我被困在其中,但我现在可以走得更远。我很感激
    猜你喜欢
    • 1970-01-01
    • 2011-02-04
    • 2016-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    相关资源
    最近更新 更多