【发布时间】:2018-01-18 12:29:50
【问题描述】:
我正在使用com.thoughtworks.binding:route:11.0.0-M4 库来管理路由,直到现在我都按照TODO example(在项目github 中提供)来实现这个东西:
Route.watchHash(currentTodoList)(new Route.Format[TodoList] {
override def unapply(hashText: String) = todoLists.find(_.hash == window.location.hash)
override def apply(state: TodoList): String = state.hash
})
但在使用的版本中,watchHash 已被弃用,根据文档,应使用Route.Hash(state).watch()。
所以,表格可以改写如下:
val route = Route.Hash[TodoList](all /* all todo lists*/)(new Route.Format[TodoList] {
override def unapply(hashText: String) = todoLists.find(_.hash == window.location.hash)
override def apply(state: TodoList): String = state.hash
})
route.watch()
但是当路由发生变化时,如何检索(绑定到)当前的待办事项列表?作为参数给出的Var(todolist) 现在是Route 的内部。
而且Route.Hash[] 是Binding[Unit],所以我不能像这样检索值:route.bind.xxx。
我错过了什么吗?
谢谢:)
【问题讨论】:
标签: scala routes scala.js binding.scala