2012-01-30 71 views
1

我正在使用包含多个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)) 
    } 
} 
+0

在功能的汽车,是不是我' .name'而不是'car.name'? – 2012-01-30 23:17:00

回答

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) 
} 
+0

我知道我的代码并不完美,主要在“displayResult”函数中,所以如果您有任何建议评论或编辑我的答案。 – 2012-01-30 21:48:55

+0

嘿克里斯,谢谢你的回复,并且运用了它的应用方法,但事实上我不认为这个解决方案是我的问题的最佳匹配。因为我在'controller.chooseCar(selectedCar.toInt)'中提交了选择的id,它将ID保存在模型中,我想通过使用'controller.chosenCar'方法来获取选中的Car,所以我将使用两个变量这是不必要的相同的ID。 – 2012-01-30 22:02:25

+0

也许你可以把valueCell放在控制器中?我没有你的项目的总体看法,但基本上,只要你有价值细节的地方,它会起作用。 – 2012-01-30 22:11:05