If you want the state to be routable (i.e. accessible via a URL), it must be serializable and deserializable through the ember router. If the state is transient and not routable, then it is probably best to keep it on the controller.
If you need to imagine the complex state of an interface for several models (for example, to select items in a list), consider supporting an array of controller-specific objects that wrap the underlying data models. I think itβs hacking to represent the state of a view directly on models, especially if these models are used in multiple views.
In the above example, you can do something similar to connect a complex route:
Ember.Route.extend({ route: "flights/:cities/dates/:dates", serialize: function(router, context){ return {cities: context.get('cities'), dates: context.get('dates')}; }, deserialize: function(router, params){
Please note that you can also use a route such as "flights? Cities =: cities and dates =: dates", but higher is probably cleaner and more optimized for SEO.
Extension after Gabriel's comments. If you want to save an array of queries, each of which is on its own tab, I would recommend storing the data for these searches in an application-level array (for example, App.currentUser. ActiveSearches). My reasoning is that you do not want to update this data every time the user switches tabs. Instead, the router will retrieve this data in deserialize() , and then pass it as a context to connectOutlets() . The view and controller for presenting this data must be quickly rebuilt based on this object when switching tabs. Let me expand my example above:
Ember.Route.extend({ route: "flights/:cities/dates/:dates", serialize: function(router, context){ return {cities: context.get('cities'), dates: context.get('dates')}; }, deserialize: function(router, params){
Dan gebhardt
source share