Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

node.js - Jade template, how to pass concrete object to pages?

I have a jade template for my node.js project. I would like to send an object to the jade template and pass it to a function inside the page (to render something).

I am sure I send the right stuff from the server like this

res.render(__dirname + '/pages/viz.jade', {
    vizJson: newJson,
});

in the client I do something like this:

script
    sunburst(#{vizJson})

Thus, inside a script function, I want to call a function that creates my visualization with some json I created on the server side.

The problem is that when rendered I have something like sunburst([Object object]). I also tried to send the stringified version of the JSON but when I do JSON.parse(#{vizJson}) it complains like Unexpected token &.

The json I send is always different and has different level of depths.

Does anyone knows what to do?

Thanks

question from:https://stackoverflow.com/questions/8437295/jade-template-how-to-pass-concrete-object-to-pages

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I hope this is going to help someone. I solved it like this:

script
    sunburst(!{JSON.stringify(vizJson)})

Notice the ! and the {...} wrapping the stringify method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...