Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js (pre4) array controller not keeping state
    primarykey
    data
    text
    <p><strong>Edit 2013-03-02</strong></p> <p>This appears to be resolved in RC1</p> <hr> <p>In previous versions of Ember.js, controllers would keep state assigned to them, but this seems to be an issue in Pre4.</p> <p>So if I were to have this controller</p> <pre><code>App.UsersController = Ember.ArrayController.extend({ content: ['mike', 'jen', 'sofia'], _content_observer: (function(){ /* I'm called, but my author doesn't know why */ console.log('Content was altered! But why? And by whom?'); }).observes('content') }); </code></pre> <p>The content is overwritten for some unexplained reason. I <strong>don't want to use ember data</strong>, but it seems like I'm being forced that direction.</p> <p>This <a href="http://jsfiddle.net/wmarbut/XSZZW/" rel="nofollow">JS Fiddle</a> exemplifies the issue.</p> <p>What's going on? How do I stop it or is this so engrained in embers opinionatedness that I need to just accept it and go with the flow?</p> <hr> <p><strong>Edit</strong></p> <p>Taking this a bit further, it appears that whatever is setup as the <code>model</code> will be set to the <code>content</code> value, even if you override the <code>setupController</code> hook.</p> <p>e.g.:</p> <pre><code>UsersRoute = Ember.Route.extend({ model: function() { /*I should never be called, but I am. How curious.*/ return ['This','Shouldnt','Be','Assigned']; }, setupController: function() { /* According to http://emberjs.com/guides/routing/specifying-a-routes-model/, I should prevent the model from being assigned to content, but I don't */ } }); </code></pre> <p>The <code>UsersController.content</code> will end up with the value <code>['This','Shouldnt','Be','Assigned']</code></p> <p>See this updated <a href="http://jsfiddle.net/wmarbut/dz98R/" rel="nofollow">fiddle</a></p>
    singulars
    1. This table or related slice is empty.
    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