Skip to content

Instantly share code, notes, and snippets.

@sukima
Created February 12, 2019 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukima/94708c3c5c98d451bf8bf7b9b9e7e1b7 to your computer and use it in GitHub Desktop.
Save sukima/94708c3c5c98d451bf8bf7b9b9e7e1b7 to your computer and use it in GitHub Desktop.
Serialize objects in QP
import Controller from '@ember/controller';
import { reads } from '@ember/object/computed';
export default Controller.extend({
queryParams: ['theObject'],
actions: {
updateTheObject() {
this.set('theObject', { appName: this.appName });
}
}
});
import Route from '@ember/routing/route';
export default Route.extend({
queryParams: {
theObject: { type: 'object' }
},
setupController(controller) {
this._super(...arguments);
controller.set('appName', 'Test');
},
serializeQueryParam(value, key, type) {
if (type !== 'object') return this._super(...arguments);
return JSON.stringify(value);
},
deserializeQueryParam(value, key, type) {
if (type !== 'object') return this._super(...arguments);
return JSON.parse(value);
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{input value=this.appName enter=(action "updateTheObject")}}
<br>
<br>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment