Note that there are some explanatory texts on larger screens.

plurals
  1. PONest knockout foreach templates
    primarykey
    data
    text
    <p>I'm trying to nest some jQuery templates. I know jQuery has the {{tmp syntax i can use, but that won't work for me as i need to use knockout's foreach template. As you can see below, i've got a div bound to the first script tag. that's my first template, using knockout's foreach syntax to loop through an observable array of messages. inside that template i'm trying to put another div bound to another template that uses knockout's foreach to loop through an array within each member of the 'messages' array. It's not working. i'm getting javascript errors (like "expected identifier"). any idea what i'm doing wrong?? </p> <pre><code> &lt;div data-bind="template: {name: 'contactIMSTemplateContent', foreach:messages}"&gt;&lt;/div&gt; &lt;script id="contactIMSTemplate" type="text/html"&gt; &lt;span class="tabTop"&gt;${viewModel.contacts()[$data.contact].name()}&lt;/span&gt; &lt;/script&gt; &lt;script id="contactIMSTemplateContent" type="text/html"&gt; &lt;div class="tabContentIM" &gt; &lt;div data-bind="template: {name:'IMSTemplate', foreach:${viewModel.messages()[$data.contact].ims}}" &gt;&lt;/div&gt; &lt;/div&gt; &lt;/script&gt; &lt;script id="IMSTemplate" type="text/html"&gt; &lt;div class="message"&gt;&lt;span class="messageFrom"&gt;${viewModel.contacts()[0].name()}&lt;/span&gt; ${$data}&lt;/div&gt; &lt;/script&gt; </code></pre> <p>My viewmodel looks like:</p> <pre><code>var viewModel = { contacts: ko.observableArray([new contact("Contact Name", "contact status", "busy", "e@t.com", "url")]), messages: ko.observableArray([{ contact: 0, ims: new ko.observableArray(["chat"]) }]) }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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