grails - Set select value in gsp -
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 ]
i iterate through programrows map ( programrow ). map value1 equivalent key in abbreviations ( list of expandos ) want set select value based on this: commented option value can understand value want assign.
view gsp:
<g:each in="${programrows}" var="programrow"> <g:select name="abbrevs" from="${abbreviations}" optionvalue="//programrow.get('key1')//" optionkey="key" class="vfucourseabbreviations"/>
how can this??
i'd put code so:
def someaction(){ def abbreviations = [ 'i', 'ii', 'iii', 'iv' ] def programrows = somelist.collect { [ key1:value1, key2:value2 ] // "value1" have pass index in "abbreviations" } [ abbreviations:abbreviations, programrows:programrows ] }
the 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>
Comments
Post a Comment