transfer data from jade to jquery and vice versa

不打扰是莪最后的温柔 提交于 2019-12-11 10:18:50

问题


My index.js file:

res.render('index', {data:{'hello':'world'}});

my jade file:

p #{data}
script(src="/javascripts/app.js")

This prints the value json object.

now on my app.js file console.log(data); gives an error saying data is undefined.

How can I access the data which was passed from my index.js file in my javascript file.


回答1:


In your index.js file:

res.render('index', {data:JSON.stringify({'hello':'world'})});

in your Jade Template:

script(type="text/javascript").
  var data = !{data};

That'll give you an object in the client-side JavaScript.



来源:https://stackoverflow.com/questions/19942890/transfer-data-from-jade-to-jquery-and-vice-versa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!