Read from JSON Array into Grails HTML Select tag -
i using grails select tag on gsp. when call backend populate guy, values comes in json array so..
[{"id":1,"display_name":"sarah's site"}, {"id":2,"display_name":"gisele's site"}, {"id":3,"display_name":"mariam's site"} ]
so want feed id list keys attribute of tag , display_name list attribute. user sees list of display names , when select 1 id passed backed controller.
not sure how this, here code staring @ now...
<g:select id="siteid" name="siteid" from="${sitenamelist}" keys="${sitenamelist}" noselection="['':'any']"/>
any suggestions appreciated.
ok, figured out. extracted 2 lists json array (results) , passed gsp view so..
def keys = []; def values = [] results.each { keys.add(it.get("id")) values.add(it.get("display_name")) } render(view: "main", model:[sitenamekeys:keys, sitenamevalues:values])
and passed these lists , keys attribute of select tag.
<g:select id="siteid" name="siteid" from="${sitenamevalues}" keys="${sitenamekeys}"
Comments
Post a Comment