我的問題也正在於此: https://gist.github.com/somanythings/8c3d34de754af311d7826ea837d160b4在與scalajs scalajs - 反應如何將一個scalajs定義的組件傳遞給一個javascript定義的組件?
在使用scalajs與japgolly的scalajs反應的(https://github.com/japgolly/scalajs-react)庫。我試圖包裝扒爐網格http://griddlegriddle.github.io/Griddle/customization.html 我想要一個自定義列,並且要做到這一點,需要傳遞包含組件的columnMetadata結構。
當我這樣做時,我可以呈現一個沒有屬性的scalajs定義組件,但是如果我嘗試通過renderP訪問屬性,或者通過renderS訪問屬性,則它們都未在render函數的作用域中定義。如果我在瀏覽器中進行調試,它們的名字是綁定的,並且具有預期的值。
當我
def renderP(f: (DuringCallbackU[P, S, B], P) => ReactElement): Out =
render($ => f($, $.props))
打破然後$.props
是不確定的
我缺少什麼?這是ReactComponentB調度中的一個簡單的打字問題。 它與https://github.com/japgolly/scalajs-react/issues/157有某種關係,我剛剛沒有看到如何?
// Confusion over how to pass a scalajs defined component to a javascript defined component
object GriddleComponentWrapper {
// for customComponent I've tried js.Any, ReactComponentU
@ScalaJSDefined
class ColumnMeta(val columnName: String, val order: Int, val customComponent: ReactClass=null) extends js.Object
}
case class GriddleComponentWrapper(results: js.Any, //Seq[Map[String, Any]],
columns: Seq[String],
columnMeta: Option[Seq[ColumnMeta]] = None,
showSettings: Boolean = true,
showFilter: Boolean = true
) {
def toJS = {
val p = js.Dynamic.literal()
p.updateDynamic("results")(results)
p.updateDynamic("columns")(columns)
p.updateDynamic("showSettings")(showSettings)
p.updateDynamic("showFilter")(showFilter)
(columnMeta).foreach { case cm => p.updateDynamic("columnMetadata")(cm.toJsArray) }
p
}
def apply(children: ReactNode*) = {
val f = React.asInstanceOf[js.Dynamic].createFactory(js.Dynamic.global.Bundle.griddle) // access real js component , make sure you wrap with createFactory (this is needed from 0.13 onwards)
f(toJS, children.toJsArray).asInstanceOf[ReactComponentU_]
}
}
object MyTestGrid {
@js.native
class ColumnMetaProps(val data: js.Object, val rowData: js.Object, val metadata: js.Object) extends js.Object
// I've tried making the Props argument js.Dynamic, and also the ColumnMetaProps above
@JSExport
val testComp = ReactComponentB[js.Dynamic]("Mine").renderP(
(sc, props: js.Dynamic) => {
//when debugging this in the browser, 'sc' and 'props' have inspectable object values with the expected members in the browser
//dev tools, BUT, they're undefined
log.info(s"what is ${sc.props}")
log.info(s"what is $props")
val string: Frag = if (!js.isUndefined(props)) props.data.toString() else "nothing!"
<.h1(string)
}).build
@JSExport
val aCompletelyStaticComponentWithNoPropsWillWork = ReactComponentB[js.Dynamic]("MyStaticComponent").renderP(
(sc, props: js.Dynamic) => <.h1("this renders!!")).build
// am I passing the right thing to columnmeta with testComp.reactClass?
val columnMeta = (new ColumnMeta("c1", 1, testComp.reactClass) :: Nil).toJsArray
val results = Seq(
js.Dynamic.literal("c1" -> "row1c1", "c2" -> "row1c2"),
).toJsArray
val component = ReactComponentB[js.Dynamic]("MyTestGrid")
.render_P {
props =>
GriddleComponentWrapper(results, columns = "c1" :: "c2" :: Nil, columnMeta = Some(columnMeta))()
}.build
def apply() = component
}
不是一個解決問題的方法,而是一種解決方法,所以我在評論而不是'回答',希望它能幫助別人。我的定製組件如下: 'val myCustomComp:js.Function = <.h1(s「some wrapper $ {props.data.toString()}」)。render }' 然後將myCustomComp傳遞給列元數據 – lbp
我對gitter提出了同樣的問題:https://gitter.im/japgolly/scalajs-react?at = 57fdda6bdfe82a365b1a71ad – jhegedus
你在哪裏將一個scalajs組件傳遞給一個js組件? https://gist.github.com/somanythings/8c3d34de754af311d7826ea837d160b4?所有我能看到的是scalajs代碼...你的意思是https://gist.github.com/somanythings/8c3d34de754af311d7826ea837d160b4#file-scalajsreactinterop-scala-L57? – jhegedus