当我使用Binding.scala,我得到错误`每个指令必须在SDE块内,我该如何解决这个问题? [英] When I use Binding.scala, I got the error `each instructions must be inside a SDE block`, how can I fix this?
问题描述
当我使用Binding.scala时,我想根据源数据 someCollection
创建一些 div
/ p>
When I use Binding.scala, I want to create some div
s according to source data someCollection
:
val someCollection = Seq("foo", "bar")
someCollection.map { item =>
<div>{item.bind}</div>
}
但是,我有一个编译器错误每个指令必须进入SDE块
。
However, I got a compiler error each instructions must be inside a SDE block
.
我该如何解决?
推荐答案
导致此错误的代码是您的 bind
表达式不能超出 @dom的范围
宏。这可能会在创建关闭时发生,可以通过以下方式解决:
The code that causes this error is that your bind
expression must not be outside of the scope of the @dom
macro. This can happen when creating a closure and can be resolved by:
- 将闭包中的代码重构为自己的
@dom
注释方法。 -
将
someCollection
转换为BindingSeq
,例如:
- Refactoring the code in the closure into its own
@dom
annotated method. Converting
someCollection
to aBindingSeq
, for example:
常量(someCollection:_ *)。map {item => < DIV> {item.bind}< / DIV> $ / $>
scalaz.Traverse
类型类(在ScalaFiddle上运行此示例)
Constants(someCollection: _*).map { item => <div>{item.bind}</div> }
TL; DR
TL;DR
@dom def renderList(data: List[Binding[String]]) = <ol>{
import scalaz.std.list._ // Type classes for List
for (b <- data) yield {
<li>{b.bind}</li>
}
}</ol>
这篇关于当我使用Binding.scala,我得到错误`每个指令必须在SDE块内,我该如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!