Reputation: 3933
What is the best way to remember the property value of a controller? Take a look here:
I want to remember if an element was expanded, but only during the current session, I don't want to save this value into the datastore. The problem is, doing the following steps:
"Album" is also collapsed! The value isExpanded
from the "Album" was lost, seems that ember recreates the controller every time. Which would we a good solution to remember the value of isExpanded
?
Upvotes: 2
Views: 258
Reputation: 336
You can add property to model
App.Artist = DS.Model.extend({
isExpanded: false, // this property will not be included into PUT request when you will save record
name: DS.attr('string'),
albums: DS.hasMany('album', {async: true})
});
and toggle it in controller
actions: {
toggleExpanded: function() {
this.toggleProperty('model.isExpanded');
}
}
http://jsbin.com/OtEBoNO/2/edit
Upvotes: 0
Reputation: 47367
If you want the value to be persisted past the lifetime of the controller then you need to save it in a controller that will stay in scope as long as you want it to live (I'm not sure what your full intent is, but if it's really a lifetime of the page value you may want to store it on the application controller)
http://jsbin.com/osoFiZi/5/edit
App.AlbumController = Ember.ObjectController.extend({
needs: ['artist'],
actions: {
toggleExpanded: function() {
this.toggleProperty('controllers.artist.isAlbumsExpanded');
}
}
});
Upvotes: 1