How can I use g:render with my g:each variable from a Map collection?

StackOverflow https://stackoverflow.com/questions/21945407

  •  14-10-2022
  •  | 
  •  

Вопрос

I have a def statusMap = HashMap<String, List<MyItem>>() that gets passed into my gsp page.

In my gsp page I have the following:

<g:each var="myList" in="${statusMap}">
  <div id="pending_list" class="onTop">
    <g:render template="/list" model="['list':"${myList.value}", 'listSize':"${myList.value.size()}"]" />
  </div>
</g:each>

But I can't seem to correctly pass myList.value and myList.value.size() into my template. I think my quotes are wrong somehow but I'm not sure.

How can I correctly pass myList.value and myList.value.size() into the list template through the model?

Это было полезно?

Решение

Since you are using a map your itteration is based on keys within that Map. So the basic syntax looks like this:

<g:each in=${yourCoolMap.entrySet()}" var="entry">
${entry.key} = ${entry.value}
</g:each>

Thus, your code will look something like this:

<g:each var="myList" in="${statusMap.entrySet()}">
  <div id="pending_list" class="onTop">
    <g:render template="/list" model="['list': myList.value, 'listSize': myList.value.size()]" />
  </div>
</g:each>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top