报 partial is not defined异常 解决方法?

node.js
ejs视图引擎中 使用partial函数:


 
    <%= title %>
   
 
 
   

<%= title %>


   

Welcome to <%= title %>


   
    <%- partial('partialItems', items) %>

 

报错:
ReferenceError: C:\Users\liango\microblog4\views\list.ejs:10
    8|     

<%= title %>

9|

Welcome to <%= title %>

>> 10|
    <%- partial('partialItems', items) %>
11| 12| 13| partial is not defined at eval (eval at (C:\Users\liango\microblog4\node_modules\ejs\lib\ejs.js:237:14), :29:342) at eval (eval at (C:\Users\liango\microblog4\node_modules\ejs\lib\ejs.js:237:14), :29:416)

原因:
  Express 3.x 不再支持partial。可以通过“include”

修改: 使用forEach,并使用include的替换就好了



 
    <%= title %>
   
 
 
   

<%= title %>


   

Welcome to <%= title %>


    <% items.forEach(function(partialItems){ %>
    <% include partialItems %>
    <% }) %>
 




Migrating from 2.x to 3.x

https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x

你可能感兴趣的:(javascript,nodejs,js)