Skip to content

Instantly share code, notes, and snippets.

@tchan
Last active October 25, 2018 06:24
Show Gist options
  • Save tchan/bc34a1cdf99ce9a013ace8bca3d25162 to your computer and use it in GitHub Desktop.
Save tchan/bc34a1cdf99ce9a013ace8bca3d25162 to your computer and use it in GitHub Desktop.
query params
import Ember from 'ember';
import { task, timeout } from 'ember-concurrency';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
queryParams: ['search', 'statuses'],
search: '',
statuses: [],
searchTask: task(function* (val) {
yield(timeout(250));
this.set('search', val);
}).restartable(),
actions: {
toggleStatus (status) {
const selectedStatuses = this.get('statuses');
if (selectedStatuses.includes(status)) {
selectedStatuses.removeObject(status);
} else {
selectedStatuses.pushObject(status);
}
console.log('statuses', this.get('statuses'));
}
},
});
import Ember from 'ember';
export default Ember.Route.extend({
queryParams: {
statuses: {
refreshModel: true
},
search: {
refreshModel: true
}
},
model(){
return $.ajax("https://www.w3schools.com/jquery/demo_ajax_load.txt");
},
serializeQueryParam(value, urlKey, defaultValueType) {
console.log('serializeQuery params', value, defaultValueType);
return this._super(value, urlKey, defaultValueType);
},
deserializeQueryParam(value, urlKey, defaultValueType) {
console.log('deserializeQuery params', value, defaultValueType);
return this._super(value, urlKey, defaultValueType);
},
});
<h1>Welcome to {{appName}}</h1>
<input type="text" value={{search}} oninput={{perform searchTask value="target.value"}} placeholder="Search stuff" />
<br>
{{input type="checkbox" change=(action 'toggleStatus' 'good')}} Good<br>
{{input type="checkbox" change=(action 'toggleStatus' 'bad')}} Bad<br>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.15.0",
"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.2.2",
"ember-template-compiler": "3.2.2",
"ember-testing": "3.2.2"
},
"addons": {
"ember-data": "3.2.0",
"ember-concurrency": "0.8.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment