[英]Unexpected token while compiling ejs i18next
I am getting the error Unexpected token ) while compiling ejs
when doing translation using i18next. 我在使用i18next进行翻译Unexpected token ) while compiling ejs
时收到错误Unexpected token ) while compiling ejs
。
I have implemented the translation using i18next, below is the following code, getting the following error when using map function 我已经使用i18next实现了翻译,下面是以下代码,使用map函数时出现以下错误
en.json
{
"title": "List of Countries",
"list":[{
"name": "Singapore",
"code": "SG"
},{
"name": "Thailand",
"code": "TH"
}]
}
index.ejs
<h4><%=t('title')%></h4> //outputs correctly
<ul>
<%=t('list').map(e=>{%>
<li><%=e.name%></li>
<%})%>
</ul>
Your ejs scripts are incorrect when iterating over the array, you need to remove the assign character when iterating and use the object "e" instead of "li" as follows: 迭代数组时,您的ejs脚本不正确,您需要在迭代时删除赋值字符,并使用对象“e”而不是“li”,如下所示:
<ul>
<%_ t('list').map(e=>{-%>
<li><%=e.name%></li>
<%_ }) -%>
</ul>
Use: 采用:
"<%_" to remove previous whitespaces when rendering the ejs “<%_”在渲染ejs时删除以前的空格
"-%>" to remove the line “ - %>”删除该行
See official ejs docs for more details 有关更多详细信息,请参阅官方ejs文档
Just remove the assign character and you are ok. 只需删除赋值字符就可以了。
<ul>
<% t.list.map(e => {%>
<li><%=e.name%></li>
<%})%>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.