I am porting a legacy system from rails into lift. It has a lot of hard-coded concatenated javascript that I would like to render into html pages.
According to this conversation here, we can use net.liftweb.http.js.JsCmds.Script object this way:
Script("""
var x = "Here's my JavaScript & it looks good";
""")
However, I got this compiler message:
error: type mismatch;
[INFO] found : java.lang.String
[INFO] required: net.liftweb.http.js.JsCmd
What is the correct way to use net.liftweb.http.js.JsCmds.Script
?
Well, the conversation is clearly wrong.
The apply
method for net.liftweb.http.js.JsCmds.Script
takes a JsCmd as a parameter - that's the source of your compiler error.
Now for that specific case, you could fix it to something like this:
Script(JsCrVar("x", new Str("Here's my JavaScript & it looks good")))
(Str is net.liftweb.http.js.JE.Str
)
As Donald stated the JsCmds.Script() method takes a JsCmd as a parameter. So you could write direct JS statements using JsRaw.
ex.
Script(JsRaw("""var x = "Here's my JavaScript & it looks good";"""))
Here's the discussion about this topic:: https://groups.google.com/forum/#!topic/liftweb/1roPxxHIFJk/discussion
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.