Simply Lift : Chapter 14 - Dynamic html tables created from DB.runQuery()
원문 : http://simply.liftweb.net/index-Chapter-14.html#toc-Chapter-14
Part 2 : 레시피(Recipes)
14장 DB.runQuery()로 생성된 동적인 html table (Dynamic html tables created from DB.runQuery())
14.1 문제점
무엇을 시도하려고 하는가:
- DB.runQuery()를 통해서 SQL 서버에 쿼리합니다.
- 결과(다중 로우와 컬럼들)를 다음과 같은 Table 구조에 넣습니다:
1<table>
2 <thead>
3 <tr><th></th></tr>
4 </thead>
5 <tbody>
6 <tr><td></td></tr>
7 </tbody>
8</table>
14.2 해결책
DB.runQuery(sql_쿼리_문자열) 메서드는 여러분의 뷰에서 보는 것처럼 table안에 넣을 (List[String], List[List[String]])를 리턴합니다.
1<table class="lift:MySnippet">
2 <thead>
3 <tr><th id="my_th">Field Name</td></tr>
4 </thead>
5 <tbody>
6 <tr id="my_tr"><td>An item</td></tr>
7 </tbody>
8</table>
그리고 스니펫은 CSS Selector Transforms(7.10 참고)를 사용하고 다음과 같습니다:
1object MySnippet {
2 def render = {
3 val (fieldNames: List[String], fieldValues: List[List[String]]) = DB.runQuery(...)
4
5 "#my_th *" #> fieldNames &
6 "#my_tr *" #> fieldValues.map(values => "td *" #> values)
7 }
8}
Comments