我正在将遗留系统从 Rails 移植到 Lift 中。它有很多我想呈现到 html 页面中的硬编码串联 javascript。
根据 this conversation在这里,我们可以这样使用 net.liftweb.http.js.JsCmds.Script 对象:
Script("""
var x = "Here's my JavaScript & it looks good";
""")
但是,我收到了这条编译器消息:
error: type mismatch;
[INFO] found : java.lang.String
[INFO] required: net.liftweb.http.js.JsCmd
net.liftweb.http.js.JsCmds.Script
的正确使用方法是什么?
最佳答案
嗯,对话显然是错误的。
net.liftweb.http.js.JsCmds.Script
的 apply
方法将 JsCmd 作为参数 - 这是编译器错误的根源。
现在对于特定情况,您可以将其修复为如下内容:
Script(JsCrVar("x", new Str("Here's my JavaScript & it looks good")))
(Str 是 net.liftweb.http.js.JE.Str
)
关于javascript - 我们如何在 lift 中使用 net.liftweb.http.js.JsCmds.Script 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11251367/