Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber update an object in an array
    primarykey
    data
    text
    <p>I have an <code>ArrayController</code> with a <code>data:[]</code> property and a template with an each loop.</p> <p>When I do</p> <pre><code>this.data.push({object}) </code></pre> <p>the data array is updated, but the view is not.</p> <p>When I do</p> <pre><code>this.data.pushObject({object}) </code></pre> <p>the data array is updated AND the view is updated too (hooray).</p> <p>When I do</p> <pre><code>this.data[0] = {new object} </code></pre> <p>the data array is updated, but the view is not.</p> <p>What is the equivalent of pushObject for this case?</p> <p>I cannot find a "updateObject" method. There is the setObjects method, but it weirdly fails. Some objects are updated and some are not.</p> <p>The objects are like:</p> <pre><code>{ item: "item", array: [1, 2, 3, 4] } </code></pre> <p>The item is always updated, and the array not always. I have nested each loops in the template; could it be a problem?</p> <p>The template is like:</p> <pre><code>{{#each data}} {{item}} {{foo}} {{#each array}} {{this}} {{/each}} {{/each}} </code></pre> <p>The way I edit is like (in the controller):</p> <pre><code>var itemToEdit = self.get('data')[0]; itemToEdit['array'] = [2, 3, 4, 5]; </code></pre> <p>Globally speaking, the problem is that the view does not re-render. When I go to another route and then back to the current route, everything is properly rendered with all the updates I made.</p> <p>** PROGRESS: When I do</p> <pre><code>self.get('data').setEach('foo', Math.random()); </code></pre> <p>the foo property is properly set and updated in the view... Where on Earth is the "set" method for a property of an array element?</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.
    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