提升:刷新/重新加载代码段

时间:2012-01-30 18:19:51

标签: scala lift

我正在使用包含多个ID的AjaxSelect。通过选择id,该id的附加信息应该显示在一个给定的表中,该表将由一个片段生成。现在我想知道哪个是刷新列表的最佳解决方案?

HTML:

<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Type</th>
        </tr>
    </thead>

    <tbody>
        <tr class="lift:MainScreen.cars">
            <td><car:name /></td>
            <td><car:type /></td>
        </tr>
    </tbody>
</table>

SCALA:

def doSelect(msg: NodeSeq) = {
  SHtml.ajaxSelect(cars.map(i => (i.no.toString, i.no.toString + ". Car")),
    Empty, {
      selectedCar =>
        controller.chooseCar(selectedCar.toInt)
        // RELOAD TABLE
    })
}

def cars(node: NodeSeq): NodeSeq = {
  val cars = controller.chosenCarFamily.cars
  cars match {
     case null => Text("There is no items in db")
     case game => game.flatMap(i =>
       bind("car", node,
            "name" -> car.name,
            "type" -> car.type))
  }
}

1 个答案:

答案 0 :(得分:3)

您应该使用ValueCellWiringUI。可以在simple_wiringinvoice_wiring找到非常好的示例。

使用WiringUI时,每次更新valueCell cell时,都会更新与WiringUI.apply(cell)关联的内容。所以它应该做的伎俩。

以下是您具体案例的示例:

<强> HTML: 和你的一样

<强> SCALA:

class MainScreen{
  def doSelect(msg: NodeSeq) // same as yours

  def cars = WiringUI.apply(controller.chosenCarFamily)(displayResult)

  def displayResult(carFamily:CarFamily)(node: NodeSeq) ={
    carFamily.cars match {
      case null => Text("There is no items in db")
      case game => game.flatMap(i =>
        bind("car", node,
          "name" -> i.name,
          "type" -> i.type))
    }
  }
}

object Controller{
  val selectedCar = ValueCell(1)
  def chooseCar = sectectedCar.set      
  val chosenCarFamily = selectedCar.lift(car:Int => //Stuff to output the family)
}