【问题标题】:How to bind to active route如何绑定到活动路由
【发布时间】: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


    【解决方案1】:

    试试route.state.bind.xxx

    Route.Hash.state

    【讨论】:

    • 哦,是的,我错过了。真的很简单。非常感谢您的快速回复。
    猜你喜欢
    • 1970-01-01
    • 2016-12-28
    • 2016-03-23
    • 2018-08-06
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 2016-02-13
    • 2018-04-08
    相关资源
    最近更新 更多