我将 EJS 与 Node.JS 一起使用,并将 JSON 对象传递给它,但需要将其作为页面中的可用对象进行访问。我从中得到了意外的令牌 o 错误:
var initData=JSON.parse(<%-JSON.stringify(list)%>);
我无法弄清楚这里出了什么问题。
这是渲染时文件中的样子:
var initData=JSON.parse([{"title":"South Hills Health System - University Health Center","adr":"200 Lothrop St,15213","coords":"40.441875,-79.960813","images":[],"tags":[],"_id":"51c0e9798384f40000000017"},{"title":"Bombay Food Market","adr":"4605 Centre Avenue, Pittsburgh, PA 15213, USA","coords":null,"images":[],"tags":["indian","groceries","ethnic","store"],"_id":"51c0519e02b7cbec73000002"}]);