scala.js - "Yield" doesn't work in binding.scala -
several days ago read binding.scala , found cool therefore decided write own single page app.
the problem i'm trying add "li" items "ul" element, seems component want doesn't see updates.
the code below:
case class movie(title: var[string], raring: var[int], watched: var[boolean]) var movies = vars.empty[movie] @dom def want = { println(movies.bind, "!@#!@#!@#!") <div class="want"> <ul> {for (movie <- movies.value) yield { <li> <div> <span> {movie.title.bind} </span> <button onclick={event: event => { event.preventdefault() movies.value.remove(movies.value.indexof(movie)) println(movies.value) }}></button> </div> </li> }} </ul> </div>
when change movies nothing happens.
update
after comment below updated code:
def remove(movie:movie) = { movies.value.-=(movie)} @dom def want = { println(movies, "!@#!@#!@#!") <div class="want"> <ul> {for (movie <- movies.bind) yield { <li> <div> <span> {movie.title.bind} </span> <button onclick={event: event => { event.preventdefault() remove(movie) }}></button> </div> </li> }} </ul> </div>
} however, code doesn't work.
please change for (movie <- movies.value)
for (movie <- movies)
.
according the scaladoc of value method:
note: method must not invoked inside
@dom
method body.
wiki
Comments
Post a Comment