Question

i have such object in my node.js backend:

dataOne = [
    {
        "x": 1,
        "y": 597
    },
    {
        "x": 2,
        "y": 298
    },
    {
        "x": 3,
        "y": 325
    }]

and i`m using this :

res.render('index', {data: dataOne})

Now, in my JADE file I have this code:

$(document).ready(function() {

        displayGraphExampleOne("#graph1", 400/4, 100/4, "basis", #{data});
    });

but #{data} is returning like : [object Object],[object Object],[object Object]

how I can parse my #{data} to javaScript?

Was it helpful?

Solution

It seems that the data is already parsed. Try serialize it then render template.

displayGraphExampleOne("#graph1", 400/4, 100/4, "basis", !{JSON.stringify(data)} );

OTHER TIPS

Though I wouldn't really recommend passing your data down like that, you could try using JSON.parse().

Something like

displayGraphExampleOne("#graph1", 400/4, 100/4, "basis", JSON.parse(#{data}));

And then you'd have to pass it down as JSON.stringify(dataOne);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top