我在http://www.digitalaholic.com/nodejs-pagination/的ejs中有代码,并希望转换为.jade,我尝试但是还不够,不能正常工作。我在nodejs和expressjs工作,我需要玉器代码。
<div class="container">
<h1>Students</h1>
<ul class="list-group">
<% students.forEach( function( student ) { %>
<li class="list-group-item"><%= student.name %></li>
<% }) %>
</ul>
<% if (pageCount > 1) { %>
<ul class="pagination">
<% if (currentPage > 1) { %>
<li><a href="/?page=1">«</a></li>
<% } %>
<% var i = 1;
if (currentPage > 5) {
i = +currentPage - 4;
} %>
<% if (i !== 1) { %>
<li class="disabled"><a href="#">...</a></li>
<% } %>
<% for (i; i<=pageCount; i++) { %>
<% if (currentPage == i) { %>
<li class="active"><span><%= i %> <span class="sr-only">(current)</span></span></li>
<% } else { %>
<li><a href="/?page=<%= i %>"><%= i %></a></li>
<% } %>
<% if (i == (+currentPage + 4)) { %>
<li class="disabled"><a href="#">...</a></li>
<% break; } %>
<% } %>
<% if (currentPage != pageCount) { %>
<li><a href="/?page=<%= pageCount %>">»</a></li>
<% } %>
</ul>
<% } %>
</div>
我的代码尝试是转换为jade的代码如下:
div(class="container")
h1 Students
ul(class="list-group")
each item in students
li(class="list-group-item") item.name
if (pageCount > 1)
ul(class="pagination")
if currentPage > 1
li
a(href="/?page=1")
var i = 1;
if currentPage > 5
i = +currentPage - 4;
if i !== 1
li(class="disabled")
a(href="#") ...
for (var i; i<=pageCount; i++)
if currentPage == i
li(class="active")
span i
span(class="sr-only") (current)
else
li
a(href="/?page=<%= i %>")
= i
if (i == (+currentPage + 4))
li(class="disabled")
a(href="#") ...
break;
if (currentPage != pageCount)
li
a(href="/?page=<%= pageCount %>")
答案 0 :(得分:2)
请准确说明什么是&#34;没有工作&#34;,你得到什么HTML,什么错误,你期待什么。
但是现在,我可以说:a(href="/?page=<%= pageCount %>")
这是EJS,这也应该被转换,然后for和break不能像我想的那样工作,但是你可以传递原始JS:
div(class="container")
h1 Students
ul(class="list-group")
each item in students
li(class="list-group-item") item.name
if (pageCount > 1)
ul(class="pagination")
if currentPage > 1
li
a(href="/?page=1")
var i = 1;
if currentPage > 5
i = +currentPage - 4;
if i !== 1
li(class="disabled")
a(href="#") ...
- for (var i; i<=pageCount; i++)
if currentPage == i
li(class="active")
span i
span(class="sr-only") (current)
else
li
a(href="/?page=" + i)
= i
if (i == (+currentPage + 4))
li(class="disabled")
a(href="#") ...
- break;
if (currentPage != pageCount)
li
a(href="/?page=" + pageCount)