【发布时间】:2019-08-02 20:54:49
【问题描述】:
我未能编译一个简单的 Binding.scala 示例,而且作为一个新手,我不知道如何解决它。也许自述文件有点过时了? https://github.com/ThoughtWorksInc/Binding.scala-sample 的示例甚至更早,并导致弃用警告。
我的代码,基本上是从 README 中拼凑起来的,甚至简化了一点:
import com.thoughtworks.binding.dom
import org.scalajs.dom.document
import scala.scalajs.js.annotation.JSExport
@JSExport
object SampleMain {
@dom
def table = {
<table border="1" cellPadding="5">
<thead>
<tr>
<th>Name</th>
<th>E-mail</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
}
@JSExport
def main(): Unit = {
dom.render(document.body, table)
}
}
fastOptJS 导致编译错误:
SampleMain.scala:25:9: overloaded method value render with alternatives:
[error] (parent: org.scalajs.dom.raw.Node,children: com.thoughtworks.binding.Binding[com.thoughtworks.binding.Binding.BindingSeq[org.scalajs.dom.raw.Node]],dummy: Unit)Unit <and>
[error] (parent: org.scalajs.dom.raw.Node,children: com.thoughtworks.binding.Binding.BindingSeq[org.scalajs.dom.raw.Node])Unit <and>
[error] (parent: org.scalajs.dom.raw.Node,child: com.thoughtworks.binding.Binding[org.scalajs.dom.raw.Node])Unit
[error] cannot be applied to (org.scalajs.dom.raw.HTMLElement, scala.xml.Elem)
[error] dom.render(document.body, table)
[error] ^
我怀疑类型推断有问题,并尝试了这种类型注释:def table: com.thoughtworks.binding.Binding[org.scalajs.dom.html.Table] 但这导致了另一个错误:
SampleMain.scala:11:6: type mismatch;
[error] found : scala.xml.Elem
[error] required: com.thoughtworks.binding.Binding[org.scalajs.dom.html.Table]
[error] (which expands to) com.thoughtworks.binding.Binding[org.scalajs.dom.raw.HTMLTableElement]
[error] <table border="1" cellPadding="5">
[error] ^
我希望能解释一下这里出了什么问题。
【问题讨论】:
标签: sbt scala.js binding.scala