【问题标题】:How to find out, why a DOM binding is rendered twice如何找出为什么 DOM 绑定被渲染两次
【发布时间】:2017-12-19 16:22:41
【问题描述】:

我得到了以下 dom 绑定:

object Modals {

  val modals = Var[Modal](null)

  def show(modal: Modal) = modals.value = modal
  def hide(modal: Modal) = modals.value = null

  @dom
  def apply() = {
    if (modals.bind != null) {
      <!-- Some static HTMLElements -->
      ... This is called twice ...
    }
  }
}

虽然 show-Method 只调用了一次(我已经用调试输出仔细检查了它),但元素被渲染了两次,所以我收到了 HTMLElements 不能插入 DOM 两次的错误消息。

找出最好的方法是什么,为什么绑定会被重新计算两次?我不知道如何调试这个......对我来说,它只取决于一个Var,并且只更改一次......

【问题讨论】:

    标签: scala scala.js binding.scala


    【解决方案1】:

    打印堆栈跟踪可能有助于跟踪源,例如您可以将以下代码放在.bind 语句下

    new RuntimeException("...").getStackTrace.take(10).map(println)

    此外,在 .bind 语句之后的旧 println(尤其是如果您有多个语句)有助于了解正在发生的事情。

    【讨论】:

      猜你喜欢
      • 2021-07-27
      • 2015-03-01
      • 1970-01-01
      • 2020-03-17
      • 2020-07-11
      • 2023-01-24
      • 1970-01-01
      • 2020-09-07
      相关资源
      最近更新 更多