在 gsp 中标记 "Select"
Tag "Select" in gsp
如何在 gsp 中正确使用标签 select
并传递给它 ArrayList<String>
?我知道如何使用我自己的组合对象,例如:
<g:select name="tablePlacesAvailable" from="${tableInfo}" optionValue="${{it.placesInTableAmount}}" optionKey="placesInTableAmount" value=""/>
但是如何将它与 built in
对象一起使用,例如 String
?
如果您想使用 g:select
和 String
列表
<g:select name="selection" from="${values}" />
其中 values
是字符串的集合。我的控制器代码是
class DemoController {
def index() {
[values: ["This", "is", "a", "test"]]
}
}
以下是一些测试及其结果:
控制器:
控制器:
def index() {
def myList=['hello','world']
def myMap=['h':'hello','w':'world']
render view: 'index', model: [myList:myList,myMap:myMap]
}
gsp:
<g:form name="test" >
<g:select name="s1" from="${['lastUpdated', 'id']}" value="${sortby}" />
<g:select name="s2" from="${['lastUpdated', 'id']}"
optionKey="value" optionValue="value" value="${sortby}" />
<g:select name="g" from="${['90%':'90%','100%': '100%']}"
optionKey="key" optionValue="value" value="${params.g}" />
<g:select name="g2" from="${myList}" />
<g:select name="g3" from="${myMap}" />
<g:select name="g4" from="${myMap}" optionKey="key" optionValue="value"/>
<g:select name="g5" from="${myMap}" optionKey="key" optionValue="key"/>
<g:select name="g6" from="${myMap}" optionKey="value" optionValue="value"/>
<g:submitButton name="go" value="post"/>
</g:form>
结果:
[g:100%, s2:lastUpdated, s1:id, g2:world, g6:world, g5:w, g4:w,
go:post, g3:w=world, action:index, format:null, controller:test]
如您所见,没有 optionKey optionValue 的 Arraylist 默认情况下有效,在 s2 中我还物理地将键值定义为值并且它仍然有效
如何在 gsp 中正确使用标签 select
并传递给它 ArrayList<String>
?我知道如何使用我自己的组合对象,例如:
<g:select name="tablePlacesAvailable" from="${tableInfo}" optionValue="${{it.placesInTableAmount}}" optionKey="placesInTableAmount" value=""/>
但是如何将它与 built in
对象一起使用,例如 String
?
如果您想使用 g:select
和 String
<g:select name="selection" from="${values}" />
其中 values
是字符串的集合。我的控制器代码是
class DemoController {
def index() {
[values: ["This", "is", "a", "test"]]
}
}
以下是一些测试及其结果: 控制器: 控制器:
def index() {
def myList=['hello','world']
def myMap=['h':'hello','w':'world']
render view: 'index', model: [myList:myList,myMap:myMap]
}
gsp:
<g:form name="test" >
<g:select name="s1" from="${['lastUpdated', 'id']}" value="${sortby}" />
<g:select name="s2" from="${['lastUpdated', 'id']}"
optionKey="value" optionValue="value" value="${sortby}" />
<g:select name="g" from="${['90%':'90%','100%': '100%']}"
optionKey="key" optionValue="value" value="${params.g}" />
<g:select name="g2" from="${myList}" />
<g:select name="g3" from="${myMap}" />
<g:select name="g4" from="${myMap}" optionKey="key" optionValue="value"/>
<g:select name="g5" from="${myMap}" optionKey="key" optionValue="key"/>
<g:select name="g6" from="${myMap}" optionKey="value" optionValue="value"/>
<g:submitButton name="go" value="post"/>
</g:form>
结果:
[g:100%, s2:lastUpdated, s1:id, g2:world, g6:world, g5:w, g4:w,
go:post, g3:w=world, action:index, format:null, controller:test]
如您所见,没有 optionKey optionValue 的 Arraylist 默认情况下有效,在 s2 中我还物理地将键值定义为值并且它仍然有效