Sails.js - passing data to a view

前端 未结 1 1243
后悔当初
后悔当初 2021-02-14 04:08

I\'ve recently started learning how to use Sails.js and I came across a small issue.

I have a model called Applicant, as follows:

module.exports = {

  a         


        
相关标签:
1条回答
  • 2021-02-14 04:48

    Try

    <%= apps[applicant].name %>
    

    It's just like for loop works. applicant is an index in apps array.

    Edit: Better way is to use javascript array's built in method forEach, because this way you avoid cycling through elements, inherited from apps's type (for example, elements, assigned like this: apps.__proto__.foo = {name: "bar"} or Array.prototype.foo2 = {name: "pi222"}).

    <% apps.forEach(function(applicant)  { %>
        <li><%= applicant.name %> <%= applicant.email %></li>
    <% }); %>
    

    P.S. Of course this javascript's method (forEach) wouldn't work in IE <= 8(if you consider to use it in browser). But we are inside NodeJs, which is built on top of V8 engine. So this will work, anyway.

    0 讨论(0)
提交回复
热议问题