0

チェックボックスがクリックされるたびに、適切な ID が check メソッドに渡されます。

  @RequestMapping(value = Array("checkBoxCheck.html"))
      @ResponseBody
      def check(@RequestParam checkBoxId: Long) {
      processing(checkBoxId) 

      }

    def processing(checkBoxId:Long){....}

上記のコードはSpring Scalaの例です。各IDをリストに追加したいのですが、すでに存在する場合は、処理メソッドでリストから削除します

4

2 に答える 2

1

「パターンマッチ」ユースケース

  def processing(list: List[Int] , id: Int): List[Int] = list match {
    case list if list.contains(id) => list filterNot(_ == id)
    case _ => list :+ id
}  
val list = List(1, 2, 3)                        //> list  : List[Int] = List(1, 2, 3)
processing(list, 3)                             //> res0: List[Int] = List(1, 2)
processing(list, 4)                             //> res1: List[Int] = List(1, 2, 3, 4)
于 2013-06-07T08:31:17.163 に答える