I am trying to render a array of object (highcharts points). The data should be fine, but when I try to render, I get [object Object]
instead of the data themselves.
JSON.stringify()
doesn t go well with HTML.
util.inspect
, doesn t either, and add data.
toString()
give me the same as the rendering.
I don t know what else to try, what I m trying to send is data for a highchart graphic.
Minimal example:
app.js:
var express = require('express'),
app = express();
app.listen(8080);
app.get('/', function (req, res) {
var view = 'test.ejs',
theme = [{name: '1', y: 5}, {name: '2', y: 2}];
res.render(view, {theme: theme});
console.log('ok');
});
theme_days.ejs:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
<%= theme %>
</script>
</body>
</html>
Result (as if, toString()
):
[object Object],[object Object]
Result with JSON.stringify()
:
[{"name":"1","y":5},{"name":"2","y":2}]
Result with util.inspect
:
[ { name: '1', y: 5 }, { name: '2', y: 2 } ]
EDIT:
I now understand that what s happenning is that '
is escaped to html, is there a way to prevent that?