【问题标题】:accessing the length of array in ejs访问ejs中的数组长度
【发布时间】:2020-06-07 02:56:08
【问题描述】:

我必须将一个数组发送到一个 ejs 文件 .Nodejs(Express) 服务器代码:

      response.redirect('file',{array : someArray });

如何在 ejs 中访问数组长度:

      <p><%= array.length %></p>

上述ejs文件中的代码不正确。这会产生错误。如何解决?

【问题讨论】:

  • 你能提供更多的服务器端代码和你得到的错误吗?

标签: node.js express ejs


【解决方案1】:
response.render('file', { array: someArray }); // in the server code

确保您的ejs 文件file.ejs 位于名为views 的文件夹中。

然后就可以访问数组length

<p><%= array.length %></p>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-17
    • 2020-03-06
    • 2017-03-10
    • 1970-01-01
    • 2018-08-21
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    相关资源
    最近更新 更多