简体   繁体   中英

How to use a object JSON from jade to local javascript?

I try to use a JSON object (all the object not just a piece) from Node through Jade inside my local myScript.js script.

And my Jade file:

span(class="glyphicon glyphicon-pencil" onclick="confirm(\"#{myJSON.taskid}\", \"update\", !{myJSON})")

But I have this:

Uncaught ReferenceError: myJSON is not defined.

Then I quit !{myJSON} as parameter in the call of function confirm() in onclick() , and I try with a script block:

script(type= "text/javascript" src="myScript.js").
    var local_json =!{JSON.stringify(myJSON)};

In myScript.js I issued console.log(local_json) , but I end up with the following error in the console: Uncaught ReferenceError: local_json is not defined .

How I can do it?

You have to first create variable , then import your script file. so basically var local_json = !{JSON.stringify(myJSON)} then import other script - script ( type = "text/javascript" src="myScript.js")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM