Note that there are some explanatory texts on larger screens.

plurals
  1. POShould marionette backbone model fields be automatically available for templates
    primarykey
    data
    text
    <p>I have a collection calling a remote REST server and getting back a JSON object containing fields including arrays. My Model is being called on each iteration through the collection, and I can get one of the fields to render in my template. Here's where things get strange...</p> <p>If I do the following in the template:</p> <pre><code>&lt;%= name %&gt; </code></pre> <p>I can get the name field to output. However, any other fields will not render, unless I create some defaults at the beginning of the Model thus:</p> <pre><code>defaults: { name: '', phone: '', age: '' } </code></pre> <p>So, if I include this, I can render those fields. Should I have to do that on a model to use it's fields?</p> <p>... as requested by n8eil</p> <p>Template:</p> <pre><code>&lt;script type="text/template" id="pos-list-item"&gt; &lt;%= name %&gt;, &lt;%= description %&gt;, &lt;%= cost %&gt; &lt;/script&gt; </code></pre> <p>JSON Object:</p> <pre><code>{ "itemCount": 3, "items": [ { "uri": "/item/1234", "name": "Soda Drink", "description": "A fizzy drink", "price": [ { "costType": "A", "cost": 3.5 } ], "live": true, "created": "2013-10-07 18:22:29" }, { "uri": "/item/12345", "name": "Choco bar", "description": "A nice snack", "price": [ { "costType": "B" "cost": 1.75 } ], "live": true, "created": "2013-10-07 18:22:29" } ] } </code></pre> <p>Changed some data for project privacy but this is essentially the layout of the JSON object. I need 'name', 'description' and 'cost' to appear in the template as above. I can log 'price' out to the console and it shows as an object but I cannot single out the 'cost' field...</p>
    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.
    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