Reputation: 4039
I have a complex array of JSON objects and I want to send that to my jade template so that so can create a visualization on the page I am rendering, but I keep having an issue with how the object is formatted.
In my controller I'm passing it like this
res.render('scatter', {
title: 'Scatter',
company: company,
graphdata: dataArray
});
in my view trying to display like this
script graphdata = "#{graphdata}";
When I log the result it looks like this
[object Object],[object Object]
when it should be an array of objects.
what am I doing wrong ?
Upvotes: 1
Views: 297
Reputation: 1723
The reason why it happens is that it tries to convert the Array into a String. If you take an array of Objects and convert them to a string, you will get this.
(Go to browser console and do this [{a:4}, {k: 9}].toString()
. And the result will be "[object Object],[object Object]"
.
If you want to display the array of Objects at it is, you can do:
"#{JSON.stringify(graphdata)}"
Upvotes: 2