admin管理员组文章数量:1394217
If you use node.js and ejs and render JavaScript object to ejs, the resultant HTML page has the following syntax:
[object Object]
despite the fact that my object is as follows:
[{"a": 3, "b": 10}, {"c":3, "d":20}, {"e":1, "f":55}]
However, I want to render the object itself (object literal if I understand it correctly), not the useless [object Object]
.
So how can I render it properly? res.render("index", {result: listOfObject.valueOf()})
didn't work.
If you use node.js and ejs and render JavaScript object to ejs, the resultant HTML page has the following syntax:
[object Object]
despite the fact that my object is as follows:
[{"a": 3, "b": 10}, {"c":3, "d":20}, {"e":1, "f":55}]
However, I want to render the object itself (object literal if I understand it correctly), not the useless [object Object]
.
So how can I render it properly? res.render("index", {result: listOfObject.valueOf()})
didn't work.
2 Answers
Reset to default 3[object Object]
is what you get when you call .toString()
on an anonymous object. This is implicitly done when you concatenate with another string (e.g. "my object: " + {a:'b'}
).
If you want to get the output you're looking for, you need to use
JSON.stringify(yourObjectHere)
Which prints it all out nicely.
res.render("index", { result: JSON.stringify(listOfObject) });
本文标签: javascriptSend object from nodejs to ejsnot object ObjectStack Overflow
版权声明:本文标题:javascript - Send object from node.js to ejs, not [object Object] - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744774180a2624524.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论