I want to bind a controller property that contains an ember-data object to a query string param. I’m using 1.6.0-beta.1+canary with the following in my controller.
I’m pretty sure @machty said Object query-params will be added “over his dead body” or maybe something about him spinning in his grave.
Serializing POJO in the url via query-params would get pretty out of hand. Someone in #emberjs asked about doing it a while back and agreed the results were nasty.
That said getting an ember-data record from a bound query-param should be pretty easy using a Computed Property.
App.MyController = Ember.ObjectController.extend({
queryParams: ['recordId']
recordId: null,
record: function(key, value) {
if (arguments.length > 1) {
//handle set by setting recordId
this.set('recordId', value.get('id');
}
return this.store.find('record', this.get('recordId'));
}.property('recordId')
});
Might be errors, but basic idea should work. Hope this helps.
Thanks for the suggestion about using a computed property, I wasn’t aware that you could handle setting the value as well. Going a step further I’ll see if I can create a mixin that would do it for any specified query params.