【发布时间】:2015-10-08 00:36:01
【问题描述】:
基本上,我正在寻找有用的 react-bootstrap 包装器。在审查不同的可能性时,我发现了this github project。我已经分叉了它们并开始更新版本。但是在将 scalajs-react 版本从 0.8.1 更新到 0.9.2 之后,我陷入了 html.Element vs dom.Element 的老套路。
Affix object 在作用域上调用 getDOMNode()
val domNode = scope.getDOMNode()
早期的 domNode 是扩展 type TopNode = html.Element,但在最新版本中,domNode 扩展 type TopNode = dom.Element 没有“className”、“offsetHeight”和“style”等值。所以我得到编译失败
[error] /Users/vl/dev/git/scalajs-react-bootstrap/core/src/main/scala/com/acework/js/components/bootstrap/Affix.scala:94: value offsetHeight is not a member of japgolly.scalajs.react.TopNode
[error] } else if (offsetBottom.isDefined && (position.top + domNode.offsetHeight >= scrollHeight - offsetBottom.get)) {
[error] ^
[error] /Users/vl/dev/git/scalajs-react-bootstrap/core/src/main/scala/com/acework/js/components/bootstrap/Affix.scala:102: value style is not a member of japgolly.scalajs.react.TopNode
[error] domNode.style.top = ""
[error] ^
[error] /Users/vl/dev/git/scalajs-react-bootstrap/core/src/main/scala/com/acework/js/components/bootstrap/Affix.scala:53: value className is not a member of japgolly.scalajs.react.TopNode
[error] var className = affixRegexp.replaceAllIn(node.className, "")
[error] ^
如何在最新的 scalajs-react 版本中管理它? (据我了解,此功能已移至单独的项目“scalajs-dom”)
【问题讨论】:
-
我不知道反应门面,所以我不知道 正确的 答案,但作为一种快速的解决方法,您可能可以使用 domNode.asInstanceOf[html.Element ] 让自己克服眼前的困难。 (当然,前提是您确信它是一个 HTML 元素。)
-
我认为这是个坏主意。
className可以替换为classList,并在源代码中进行了一些修复。我不知道如何替换offsetHeight和style。但也许它会起作用。会尝试... -
几个月前我还尝试升级到 0.9.1。这是一个叉子github.com/simerplaha/scalajs-react-bootstrap ...但我似乎无法找到您在 Affix.scala 中遇到的问题。我们在生产中使用 fork 版本已经有一段时间了,但我建议你也看看github.com/payalabs/scalajs-react-bridge,它使用宏来生成 React 组件(更容易!)。
-
@CMR 我查看了你的分叉,发现有用的隐式
import japgolly.scalajs.react.extra.DefaultReusabilityOverlay.autoLiftHtml基本上将dom.Element转换为html.Element,正如@Justin du Couer 上面提到的那样。感谢您的建议。
标签: scala scala.js react-bootstrap scalajs-react