当我使用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?

查看:205
本文介绍了当我使用Binding.scala,我得到错误`每个指令必须在SDE块内,我该如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Binding.scala时,我想根据源数据 someCollection 创建一些 div / p>

When I use Binding.scala, I want to create some divs 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:


  1. 将闭包中的代码重构为自己的 @dom 注释方法。

  2. someCollection 转换为 BindingSeq ,例如:

  1. Refactoring the code in the closure into its own @dom annotated method.
  2. Converting someCollection to a BindingSeq, 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆