I have a Scala.js application using Udash. The application is using some Bootstrap extensions, which directly manipulate HTML DOM. I would like to traverse this DOM and add some more handlers to it (eventually I would like the handlers to implement Udash binding). My trouble is the only way I can do this is by inserting a script
tag, which expects me to provide a plain Javascript code.
Is there some way I could call by Scala.js code from this Javascript? Normally I would export a global function and pass any necessary parameters to it, however I do not see any clean way how to pass this
, the only way I can think of is using a global variable, which look super ugly to me. Is there anything like local exports, or some other way how to create a JavaScript code I could pass into script
which would be able to access Scala.js constructs?
My current code looks like this:
// somewhere in class ExtTable .. in the `render` method
div(
p(id := componentId, "Html constructed here"),
script {
ExtTable.callback = { e =>
println(s"JS Callback for $e on $this")
}
//language=JavaScript
s"""
// I would like to implement this in Scala.js instead
var t = $$('#${componentId.toString}');
t.bootstrapTable();
t.find("tr td:first-of-type").each(function(i,e){
ExtTable.callback(e);
})
"""
}
).render
@js.annotation.JSExportTopLevel("ExtTable")
object ExtTable {
@js.annotation.JSExport
var callback: js.Function1[Element, Unit] = _
}