我有一个Vars
绑定语句,就像一样
val data: Vars[Contact] = Vars.empty[Contact]
我试图显示元素的数量,比如:
<div>{data.all.bind.size}</div>
但这会产生一个复杂的错误
type mismatch;
[error] found : com.thoughtworks.binding.Binding[App.this.data.All[App.this.Contact]]
[error] (which expands to) com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_ <: App.this.Contact]]
[error] required: com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_$6]] where type _$6 <: App.this.Contact
[error] {this.data.all.bind.size}</div>
如何做到这一点?
更新
尝试使用String
作为Vars
结合的类型,相同的结果
type mismatch;
[error] found : com.thoughtworks.binding.Binding[App.this.data.All[String]]
[error] (which expands to) com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_ <: String]]
[error] required: com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_$6]] where type _$6 <: String
[error] {this.data.all.bind.size}</div>
请注意,我使用的是Scala.js 1.2、Scala 2.13.3和libraryDependencies += "org.lrng.binding" %%% "html" % "latest.release"
不幸的是,由于它不支持Scala2.13,所以无法提供scalafiddle,相反,我在这里创建了一个复制项目-https://www.dropbox.com/s/i9dpsa9pz0lejtj/bindingreplica.tar.gz?dl=0
您可以为此使用length
。
<div>{data.length.bind.toString}</div>