Jade template, how to pass concrete object to pages?

后端 未结 4 551
小鲜肉
小鲜肉 2020-12-08 06:45

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

4条回答
  •  生来不讨喜
    2020-12-08 07:27

    For this to work, you need to stringify on the server.

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

    Then, as you mentioned, parse the JSON on the client.

    script
        sunburst(JSON.parse(#{vizJson}))
    

    Hope that helps!

提交回复
热议问题