loops - How to pass a List of Maps to a GSP page view and iterate over it -


let's want show information files of folder. have save information of each file in map. then, add these maps list.

controller action:

def show() {      list results = new arraylist();      file dir = getdir(params.id);      if (dir.exists()) {         dir.eachfile {           map fileinformation= new java.util.linkedhashmap()          fileinformation.put("name", it.getname());         fileinformation.put("size", it.length());         fileinformation.put("path", it.getabsolutepath() );          results.add(fileinformation);          }     }      [filesoffolderdata: result] } 

maybe, best attempt data in view (i followed approach of here no luck):

<g:each in="${filesoffolderdata}">      <p> it: ${it}</p>     <p> it.properties: ${it.properties} </p>      <g:each var="propertyentry" in="${it.properties}">          <p> propertyentry.key: ${propertyentry.key} </p>         <p> propertyentry.value: ${propertyentry.value} </p>         <p> propertyentry.value.name: ${propertyentry.value} </p>                 </g:each>  </g:each> 

this internet browser shows (note: first line of result little bit different simplify code guest result in base of real result of case):

it: [{name=wololo1, size=35, path=c:\}, {name=wololo2, size=35, path=c:\}]  it.properties: {class=class java.util.arraylist, empty=false}  propertyentry.key: class  propertyentry.value: class java.util.arraylist  propertyentry.value.name: class java.util.arraylist  propertyentry.key: empty  propertyentry.value: false  propertyentry.value.name: false  

how iterate on list?

with each in maps have access key , value, iterate on value.

<g:each in="${filesoffolderdata}" var="files">   <g:each in="${files.value}" var="file">     ...   </g:each> </g:each> 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -