Dear all,
I am trying the Hands-On Tutorial and things work relatively well up to here:
http://www.lihaoyi.com/hands-on-scala-js/#InteractiveWebPages
I have included some Scalatags as instructed in my code and see no widgets on the HTML – even though the compiler is happy both in the terminal and the workbench output on the page. For the reference, I am putting the relevant files in the P.S. Does anyone know what’s going wrong?
TIA,
–Hossein
P.S.
- workbench-example-app\build.sbt:
enablePlugins(ScalaJSPlugin, WorkbenchPlugin)
name := "Example"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.9.1",
"com.lihaoyi" %%% "scalatags" % "0.6.2"
)
- workbench-example-app\src\main\resources\index-dev.html
<!DOCTYPE html>
<html>
<head>
<title>Example Scala.js application</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body style="margin: 0px">
<div>
<canvas style="display: block" id="div" width="255" height="255"/>
</div>
<script type="text/javascript" src="../example-fastopt.js"></script>
<script type="text/javascript" src="/workbench.js"></script>
<script>
webpage.Search0().main(document.getElementById('div'));
</script>
</body>
</html>
- workbench-example-app\project\build.sbt
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.13")
addSbtPlugin("com.lihaoyi" % "workbench" % "0.3.0")
-
workbench-example-app\src\main\scala\webpage\Search0.scala
package webpage
import org.scalajs.dom
import dom.html
import scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
@JSExport
object Search0 extends{
@JSExport
def main(target: html.Div) = {
val listings = Seq(
"Apple", "Apricot", "Banana", "Cherry",
"Mango", "Mangosteen", "Mandarin",
"Grape", "Grapefruit", "Guava"
)
def renderListings = ul( for { fruit <- listings if fruit.toLowerCase.startsWith(box.value.toLowerCase) } yield li(fruit) ).render lazy val box = input( `type`:="text", placeholder:="Type here!" ).render val output = div(renderListings).render box.onkeyup = (e: dom.Event) => { output.innerHTML = "" output.appendChild(renderListings) } target.appendChild( div( h1("Search Box!"), p( "Type here to filter " + "the list of things below!" ), div(box), output ).render ) }
}