我没有编译一个简单的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] ^
我很感激解释这里出了什么问题。