Closed hcl123 closed 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>
<% }); %>
If you have more questions about EJS please try Stack Overflow or if it's a bug then try the EJS issues.
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] %>
<% } %><%= thing %>
<% }); %>
Could pass Json(that is a array) data to Ejs directly???