scalatags.Text.all._和scalatags.JsDom.all._包的区别和用途是什么?
在official scalatags tutorial中,您可以阅读:
// import scalatags.Text.all._
// OR
// import scalatags.JsDom.all._
html(
head(
script(src:="..."),
script(
"alert('Hello World')"
)
),
body(
div(
h1(id:="title", "This is a title"),
p("This is a big paragraph of text")
)
)
)
And turns them into HTML like this:
<html>
<head>
<script src="..."></script>
<script>alert('Hello World')</script>
</head>
<body>
<div>
<h1 id="title">This is a title</h1>
<p>This is a big paragraph of text</p>
</div>
</body>
</html>发布于 2016-09-25 16:55:29
在DOMBackend和Internals部分的scalatags文档中描述了不同之处。
在使用scalatags.Text包时,结构直接呈现为String,但在使用scalatags.JsDOM包时,结构呈现为org.scalajs.dom.raw.Element的子类型(它在scalatags之外-它是scalajs库的一部分)。在处理Element时,可以进一步使用manipulate dom structure very low level of abstraction。
在这里,当使用scalatags.Text.时,h1会呈现为String
import scalatags.Text.all._
val x: String = h1("some header").render
//x is a String但在这里,当使用scalatags.JsDom时,h1会呈现为org.scalajs.dom.raw.HTMLHeadingElement
import scalatags.JsDom.all._
val x: Heading = h1("some header").render
//x is type of Heading, which is defined as:
//type Heading = raw.HTMLHeadingElement
//raw.HTMLHeadingElement is org.scalajs.dom.raw.HTMLHeadingElementhttps://stackoverflow.com/questions/39684711
复制相似问题