express 3.x 版本的 转换为4.x 版本的,要用include替代partial(用于迭代一个数组)
果断抛弃partial插件,在Express
3.x中加入了include方法,可以把原来的代码: 1 <ul><%- partial('listitem', items) %></ul>   换成如下代码: <ul><% items.forEach(function(listitem){ %> <% include listitem %> <% }) %></ul>

设置路由规则
  
  var express = require('express');
  var router = express.router();
  //
  router.get('/list',function(req,res){
    res.render('list',{title:'这是一个列表',items:['Marico','Lily','Lucy','Jimmy']});
  });

视图

  创建一个list.ejs文件,listitem.ejs文件
  
  list.ejs
  
    -- <ul><% items.forEach(function(listitem){ %>
        <% include listitem %>
        <% }) %></ul>

  listitem.ejs

    --<li><%= listitem %></li>

 

相关文章:

  • 2022-12-23
  • 2021-05-19
  • 2021-07-23
  • 2021-11-25
  • 2022-01-26
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
猜你喜欢
  • 2021-07-18
  • 2021-11-25
  • 2021-05-26
  • 2021-09-16
  • 2021-08-20
相关资源
相似解决方案