gpt4 book ai didi

grails - 在gsp中设置选择值

转载 作者:行者123 更新时间:2023-12-02 15:23:20 24 4
gpt4 key购买 nike

Controller :

     def abbrev = [:]
abbrev.put(1,"I")
abbrev.put(2,"II")
abbrev.put(3,"III")
abbrev.put(4,"IV")
List<Expando> abbreviations = abbrev.collect{
abbreviation -> Expando.newInstance(key:abbreviation.key,value:abbreviation.value)
}

def row = [:]
def programRows = [ ]

somelist.each {
item -> row = [key1:value1, key2,value2 ]
programRows << row
}

[abbreviations:abbreviations, programRows:programRows ]

我通过programRows进行迭代,所以我得到了一张 map (programRow)。
map value1等效于缩写键(Expandos列表),因此我想基于此设置选择值:我评论了选项值,以便您可以理解要分配的值。

查看gsp:
    <g:each in="${programRows}" var="programRow">
<g:select name="abbrevs" from="${abbreviations}" optionValue="//programRow.get('key1')//" optionKey="key" class="vfuCourseAbbreviations"/>

我怎样才能做到这一点??

最佳答案

我将您的代码放入:

def someAction(){
def abbreviations = [ 'I', 'II', 'III', 'IV' ]
def programRows = somelist.collect {
[ key1:value1, key2:value2 ] // as "value1" you have to pass the index in "abbreviations"
}
[ abbreviations:abbreviations, programRows:programRows ]
}

GSP:
<g:each in="${programRows}" var="programRow">     
<select name="abbrevs">
<g:each in="${abbreviations}" var="abbr" status="i">
<option value="${i}" ${i == programRow.key1 ? 'selected' : ''}>${abbr}</option>
</g:each>
</select>
</g:each>

关于grails - 在gsp中设置选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32095322/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com