2012-05-06 135 views
0

我正在用Play Framework 2.0開發一個應用程序。Play框架處理表信息

我有一個濾波部分,其在表上返回幾個結果,並在每一行我有一個這樣的詳細信息按鈕:

@(logList: List[Log]) 

@import helper._ 
@import helper.twitterBootstrap._ 

@title = { 
    Results... 
} 

@main(title, nav = "filter") { 

<table class="table"> 
    <thead> 
     <tr> 
          <th>Id</th> 
      <th>Date</th> 
      <th>Hour</th> 
      <th>Event</th> 
     </tr> 
    </thead> 
    <tbody> 
    @helper.form(action = routes.LogDetail.submit) { 
     @logList.map { log => 
     <tr> 
          <td>@log.id</td> 
      <td>@log.date</td> 
      <td>@log.time</td> 
      <td>@log.event</td> 
      <td> 

      <input type="submit" class="btn primary" value="Details"> 

      </td> 
     </tr> 
     } 
     } 
    </tbody> 
</table> 
} 

做什麼樣的變化,我需要傳遞一個行的id作爲該行的細節按鈕被按下?

感謝

回答

4

我爲什麼您使用的形式,即使你不發送任何東西得不到?實際上,對於每一行,您應該使用單獨的表單並使用隱藏字段,正如Li-o向您展示的那樣。

相反,它是隻是更容易使用普通的GET

<a href="@routes.LogDetails.show(log.id)" class="btn">Details</a> 

在Twitter的引導,你也可以將鏈接顯示爲按鈕

+0

去爲無國籍/ REST類型的解決方案。在URL /路線中設置ID。 –

+0

事實上,如果他沒有發送任何數據,他應該使用GET。 –

1

創建一個隱藏的輸入字段內您構成:<input type="hidden" name="id" value="@log.id">