简体   繁体   English

如何解析EJS模板中的数组

[英]How to parse an array inside EJS template

I get a list of ID's from API, that needs to be added to a URL inside an EJS template, so I can fetch the correct items. 我从API获得了一个ID列表,需要将其添加到EJS模板中的URL,这样我才能获取正确的项目。

Example URL: http://url.com/get/:id 示例网址: http//url.com/get/id

Example ID's: 526 876 929 示例ID:526 876 929

needed result inside EJS template: EJS模板中需要的结果:

<li> http://url.com/get/526 </li>
<li> http://url.com/get/876 </li>
<li> http://url.com/get/929 </li>

I got the list of ID's as needed, but I can't figure out why my forEach loop won't return the URL+ID. 我根据需要获得了ID列表,但我无法弄清楚为什么我的forEach循环不会返回URL + ID。

This is console.log of message: 这是console.log消息:

[ 526, 876, 929 ]

This is the EJS file: 这是EJS文件:

<% var itemurl = "http://url.com/get/" %>

<% message.forEach(itemView) => { %>
    <%= item url + itemView %>
<% }); %> 

I keep getting syntax errors and obviously I'm missing something. 我不断收到语法错误,显然我错过了一些东西。

<% var message  = [112,232,533] %>
<% var itemurl = "http://url.com/get/" %>

<% message.forEach((itemView) => { %>
    <%= itemurl + itemView %>
<% }); %>

you were missing an open parenthesis and had a space in itemurl 你错过了一个开括号并在itemurl中有一个空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM