GSP页面的g:select可用来创建HTML的select标签
g:select属性:
from select的范围
optionKey 用于生成HTML select标签中option元素中的value属性
optionValue 用于生成HTML select标签中option元素显示内容
<g:form enctype="multipart/form-data" class="form-horizontal" method="post" controller="test" action="template">
<label for="tempName" class="control-label col-sm-2">导入模板:</label>
<div class="col-sm-4">
<g:select name="tempName" id="tempName" class="form-control" from="${templateList}"
optionKey="value" optionValue="name">
<option value="">请选择导入模板</option>
</g:select>
</div>
</g:form>
从后台testController的template方法中获取templateList。TestController.groovy中方法:
def template(){
def tempList = getImportTemplateList()//该方法自行实现,List中每个对象中的Key对应前端optionKey,Key对应的属性值对应前端optionValue
[templateList: tempList]//将后台获取的tempList传到gsp
}