Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get Mustache to render this data
    text
    copied!<p>I am new to the mustache template library and have the following scenario. I am retrieving both a template and the data from a web server. I am trying to combine the two using the following code:</p> <pre><code>function formatSearchResults(results) { dojo.xhrGet({ url:"search_result_template.mch", handleAs:"text", load: function(template) { //Load the template into a hidden div on the page var templateNode = dojo.byId("templateArea") templateNode.innerHTML = template; } }); var templateNode = dojo.byId("templateArea"); var formattedResults; formattedResults = Mustache.to_html(templateNode.innerHTML,results); var templateNode = dojo.byId("outputArea"); outputArea.innerHTML = formattedResults; } </code></pre> <p>Retrieving the json and the template work fine. But the mustache never renders my data.</p> <p>I have this json data:</p> <pre><code>{ "data": [ { "ColumnValues": { "_0": "Bubbles", "_1": "Thompson%20Trucking", "_2": "A633937432DF91212431251256D350", "_3": "Eagleton", "_4": "CA", "_5": "555-555-5555", "_6": "12121", "_7": "Midatlantic", "_8": "Thompson%20Trucking..&lt;snip&gt;, "_9": "" } }, &lt;snip&gt; ] } </code></pre> <p>and this mustache template:</p> <pre><code>&lt;table id="orgInfo"&gt; &lt;tr&gt; &lt;th&gt;Search results: &lt;br/&gt;&lt;br/&gt;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Organization&lt;/td&gt; &lt;td&gt;City&lt;/td&gt; &lt;td&gt;State&lt;/td&gt; &lt;td&gt;Phone&lt;/td&gt; &lt;td&gt;Region&lt;/td&gt; &lt;td&gt;Industry&lt;/td&gt; &lt;td&gt;Description&lt;/td&gt; &lt;/tr&gt; {{data}} {{#ColumnValues}} &lt;tr&gt; &lt;td&gt;{{_0}}&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;Region&lt;/td&gt; &lt;td&gt;Industry&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; {{/ColumnValues}} {{/data}} </code></pre> <p></p> <p>and this is the output I get:</p> <pre><code>{{/data}} Search results: Organization City State Phone NAICS Region Industry Description NAICS Region Industry` </code></pre> <p>I have been over the docs and examples for hours. Can anybody tell me what I am doing wrong?</p> <p>Thanks!</p> <p>Kelvin</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload