grails使用select标签输出多个内容
2015-08-18 13:22
435 查看
http://www.tuicool.com/articles/7JRVv2
When we run the application and open the page in a web browser we get the following HTML source:
<%@ page import="com.mrhaki.grails.sample.Book" contentType="text/html;charset=UTF-8" %><html><head> <title>Simple GSP page</title> <meta name="layout" content="main"/> <style> p { margin-top: 20px; margin-bottom: 5px;} </style></head><body> <h1>Select</h1> <p>Use title property of book for option values</p> <g:select from="${Book.list()}" optionKey="id" optionValue="title" name="bookSimple"/> <p>Use closure for optionValue</p> <g:select from="${Book.list()}" optionKey="id" optionValue="${{ book -> "${book.title} - ${book.isbn}" }}" name="bookCustom"/> <g:set var="bookOptionValueFormatter" value="${{ book -> "${book.title} (${book.isbn}, ${book.numberOfPages})" }}"/> <p>Use bookOptionValueFormatter that is defined as variable on this page</p> <g:select from="${Book.list()}" optionKey="id" optionValue="${bookOptionValueFormatter}" name="bookVar"/> <p>Use bookFormatter that is passed as a model property from SampleController.</p> <g:select from="${Book.list()}" optionKey="id" optionValue="${bookFormatter}" name="bookModel"/></body></html>
When we run the application and open the page in a web browser we get the following HTML source:
...<h1>Select</h1><p>Use title property of book for option values</p><select name="bookSimple" id="bookSimple" > <option value="1" >It</option> <option value="2" >The Stand</option></select><p>Use closure for optionValue</p><select name="bookVar" id="bookCustom" > <option value="1" >It - 0451169514</option> <option value="2" >The Stand - 0307743683</option></select><p>Use bookOptionValueFormatter that is defined as variable on this page</p><select name="bookVar" id="bookVar" > <option value="1" >It (0451169514, 1104)</option> <option value="2" >The Stand (0307743683, 1472)</option></select><p>Use bookFormatter that is passed as a model property from SampleController.</p><select name="bookModel" id="bookModel" > <option value="1" >It (pages: 1104)</option> <option value="2" >The Stand (pages: 1472)</option></select>...
相关文章推荐
- 【转载】Neural Networks for Digit Recognition with Pybrain
- Open drain & push pull 原理
- sgu-300.Train
- POJ 2585 Window Pains【拓扑】
- 注解(annotaion)一对一、一对多、多对一
- LightOJ 1038-Race to 1 Again(概率dp)
- Contains Duplicate II
- Contains Duplicate
- Run-Time Check Failure #2 - Stack around the variable 'cmd' was corrupted 的可能原因
- org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role
- 【优先队列】POJ2010- Moo University-Financial Aid
- 2015 HUAS Summer Trainning #6~L
- hdu 5380 Travel with candy 单调队列 2015 Multi-University Training Contest 8
- wait_event_interruptible 使用方法
- [LeetCode] Contains Duplicate II
- 如何使用KeyChain保存和获取UDID
- IE8下MSPAINT保存的PNG显示不正常
- Aicrack-ng破解WPA/WPA2
- wait、notify、notifyAll
- 基于淘宝开源Tair分布式KV存储引擎的整合部署