0
votes

I have the following template setup displaying a list of items, and wrapping each list in its own controller:

{{#each controller itemController="contact"}}
  <div class="contact-entry">
    <div class="title" {{action toggle on="click"}}>{{title}}</div>
    {{#if showDetails}}
    <div class="details">
      <div>{{safe details}}</div>
    </div>
    {{/if}}
  </div>
{{/each}}

The main controller is an ArrayController called ContentsController, and each item is wrapped in an ObjectController called ContentController. The content of the ContentsController is set explicitly in the route (I've simplified the data):

App.ContactsRoute = Em.Route.extend({
  model: function() {
   return [{'title': 'first'}, {'title': 'second'}];
  }
});

This works really well. However if I navigate to another path and then back again, the settings on the ContentController don't persist. What happens is that the model data gets reloaded, and I assume a ObjectController gets created for each of the list items. Incidentally this is not the case for the ContentsController, which keeps its settings.

What is the solution to preventing ember of creating new ContentController for every list item every time I access the page?

1

1 Answers

0
votes

I'm assuming your reference to ContentController is really ContactsController since you are using itemController="contact" in your #each block.

What kind of data are you trying to persist? The showDetails flag? The ContactControllers are going be created and destroyed anytime you exit / enter the route and there isn't anyway I know of to keep those around.

The ContactsController keeps its properties because its a singleton controller generated because you have a ContactsRoute.