title: pass google script object to html template
body: <p>I working on standalone web app in google script using HtmlService. Here's the part of code:</p>
  
  <p>script:</p>
  
  <pre><code>function doGet() {
   getLabelsLists();
    return HtmlService
        .createTemplateFromFile('index')
        .evaluate().setSandboxMode(HtmlServi‌​ce.SandboxMode.NATIVE);
  }
  
  function getEmails() {
    var query = ...;
    var threads = GmailApp.search (query);
    return threads;
  } 
  </code></pre>
  
  <p>index.html:</p>
  
  <pre><code>&lt;? var data = getEmails(); ?&gt;
  &lt;table&gt;
    &lt;? for (var i = 0; i &lt; data.length; i++) { 
    var message = data[i].getMessages()[0];
    ?&gt;
      &lt;tr onclick= click(&lt;?= message.getId() ?&gt;)&gt;
          &lt;td&gt;&lt;?= message.getSubject() ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;? } ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>What I want to do is show only button like below on page load and on click call function that render table with a results.</p>
  
  <pre><code> &lt;input type="button" onclick="google.script.run.getEmails()" /&gt;
  </code></pre>
  
  <p>Any ideas how I can pass the array of gmail threads from getEmails() function to the view and dynamically create table?</p>