Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing an associative array to jTemplates as a parameter
    text
    copied!<p>I've created a jTemplate to display an array of "test" objects. The array is a regular indexed array. The template is very basic, just uses a <code>{#foreach}</code> to iterate through the items in the array and displays them in a small table. This template dos the job and I get the expected output. </p> <pre><code> // Setup the JTemplate. $('#tests_div').setTemplate($('#tests_template').html()); try { // Process the JTemplate to display all currently selected tests. $('#tests_div').processTemplate(_selectedTests); } catch (e) { alert('Error with processing template: ' + e.Description); } &lt;script type="text/html" id="tests_template"&gt; {#foreach $T as tests} &lt;table&gt; &lt;tr&gt; &lt;td&gt;Index: {$T.tests.index}&lt;/td&gt; &lt;td&gt;Name: {$T.tests.firstname} {$T.tests.lastname}&lt;/td&gt; &lt;td&gt;Score: {$T.tests.score} &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; {#/for} &lt;/script&gt; </code></pre> <p>What I'd like to do is change my array to be an associative array and store my objects in it using the test's index. This makes it easier to work with when I need to do some manipulation of the tests later on. </p> <pre><code>var a = new Test; a.index = 12345678; _selectedTests[a.index] = a; </code></pre> <p>However, when I pass the array to the template, I get an error about the script is causing my browswer to run slow, asking if I would like to stop it. It seems like its in some kind of endless loop. I'm not sure the template is reading the array correctly. Can anyone tell me how I work with the associative array inside the jTemplates? </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