RandomEtc / ejs-locals

Express 3.x layout, partial and block template functions for the EJS template engine.
298 stars 63 forks source link

help #23

Closed hcl123 closed 11 years ago

hcl123 commented 11 years ago

Could pass Json(that is a array) data to Ejs directly???

RandomEtc commented 11 years ago

In your app:

   app.get('/my-page',function(req,res){
       res.render('my-page', { things: [ 'my', 'list', 'of', 'things' ] });
   });

In my-page.ejs:

   <% for (var i = 0; i < things.length; i++) { %>
       <p><%= things[i] %></p>
   <% } %>

Or

   <% things.forEach(function(thing){ %>
       <p><%= thing %></p>
   <% }); %>
RandomEtc commented 11 years ago

If you have more questions about EJS please try Stack Overflow or if it's a bug then try the EJS issues.

hcl123 commented 11 years ago

In the express,how to send json to the server? For example ,when i click a button ,then i want to send json data to the server,and i can save the data in mysql database? Can you give me some advice?

------------------ 原始邮件 ------------------ 发件人: "Tom Carden"notifications@github.com; 发送时间: 2012年12月13日(星期四) 晚上11:28 收件人: "RandomEtc/ejs-locals"ejs-locals@noreply.github.com; 抄送: "hcl123"1106211282@qq.com; 主题: Re: [ejs-locals] help (#23)

In your app: app.get('/my-page',function(req,res){ res.render('my-page', { things: [ 'my', 'list', 'of', 'things' ] }); });

In my-page.ejs: <% for (var i = 0; i < things.length; i++) { %>

<%= things[i] %>

<% } %>
Or <% things.forEach(function(thing){ %>

<%= thing %>

<% }); %>
— Reply to this email directly or view it on GitHub.