title: How I access a variable from JavaScript and Grails?
body: <p>I have a <a href="http://en.wikipedia.org/wiki/Grails_%28framework%29" rel="nofollow">Grails</a> variable which is of type JASONList that is rendered in a template.</p>
  
  <p>Is there a way to access this list from inside a JavaScript function?</p>
  
  <p>Let's say I want onresize to fit all the objects on the screen. Without making a database call and refetching the entire list from Ajax...</p>
  
  <p>Let's say the template does something like this:</p>
  
  <pre><code>&lt;g:each var="report" in="${reportList?.myArrayList}"&gt;
    &lt;li style="display:inline; list-style:none;"&gt;
      &lt;img src="  ${report?.img}"&gt;
    &lt;/li&gt;
  &lt;/g:each&gt;
  &lt;script type="text/javascript"&gt;
      function resize(list) {
          if (list.size &lt;givenSize) // Pseudocode
              list.subList() // Pseudocode
      }
      window.onresize = resize("${reportList}")
  &lt;/script&gt;
  </code></pre>
  
  <p>The problem with this is that for some reason Grails gsp does not render "${reportList}" as a list. Instead it renders it as the string "${reportList}".</p>
  
  <p>I am probably thinking of this problem completely wrong, but is there a way to resize these objects or get them through document.getElementById or something of that nature?</p>
  
  <p>The $reportList is populated by <a href="http://en.wikipedia.org/wiki/Plain_Old_Java_Object" rel="nofollow">POJO</a> as JSON conversion...</p>