Where should I store ViewState specific information? On the model?


#1

Hello

I’ve an ItemList with an extandable area with detailed information. This inforrmation are lazy loaded when they are required.

My querstion is, where should I store the information that the detail part is visible? Currently i store it on the model, which works good, but has some side-effects:

When I have multiple ItemListes, a specific Item will have the same state on all lists, which isnt logicall!

When I go away from the list and come back, the states are remembered. This could be the wanted behaviour, not necessarily.

I can not easy store it on the Controller, because i’ve just one controller for the entire list. So I need to store it item specific. This looks very complicated.

From User-side the route looks like a good place, but what if i’ve no route because I render the list with the {{render}} helper?

So, whats the best place?

Thanks for help, and always thanks to the ember team!

Example: http://jsfiddle.net/d7pTs/1/


#2

You should use the itemController option of the {{each}} helper to specify a controller for each item. From the Ember docs:

http://emberjs.com/api/classes/Ember.Handlebars.helpers.html#method_each

App.DeveloperController = Ember.ObjectController.extend({
  isAvailableForHire: function(){
    return !this.get('content.isEmployed') && this.get('content.isSeekingWork');
  }.property('isEmployed', 'isSeekingWork')
})
{{#each person in developers itemController="developer"}}
  {{person.name}} {{#if person.isAvailableForHire}}Hire me!{{/if}}
{{/each}}

#3

Ok, that makes it a bit more logical, to access the item on the controller, but there is still the problem that the state is stored on the model, and so over all itemlists the same.

I’ve updated the jsFiddle, to use the itemController specification in the {{each}} helper, and to demonstrate the problem: http://jsfiddle.net/d7pTs/2/

If i toggle the primus on the favourites list, its also toggled on the newlist.