Skip to content

Instantly share code, notes, and snippets.

@baroquon
Last active October 4, 2016 19:45
Show Gist options
  • Save baroquon/f734c834c3c03258e7d790cd0f57575d to your computer and use it in GitHub Desktop.
Save baroquon/f734c834c3c03258e7d790cd0f57575d to your computer and use it in GitHub Desktop.
checked thingy
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
locations: [
Ember.Object.create({id: 1,name: `me - 1`, merchantId: 1 }),
Ember.Object.create({id: 2,name: `me - 2`, merchantId: 1 }),
Ember.Object.create({id: 3,name: `me - 3`, merchantId: 2 }),
Ember.Object.create({id: 4,name: `me - 4`, merchantId: 2 }),
],
searchTerm: null,
locationsObject: Ember.computed('locations', 'searchTerm', function() {
let _obj = [];
this.get('locations').forEach((location) => {
let locObj = {
id: location.get('id'),
name: `${location.get('name')} - ${location.get('merchantId')}`,
checked:true,
merchantId: location.get('merchantId')
};
_obj.push(locObj);
});
return _obj;
}),
checked: Ember.computed('[email protected]', function() {
let _checked = [];
this.get('locationsObject').forEach((_location) => {
if (_location.checked) {
_checked.push(_location.id);
}
});
return _checked;
}),
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{#each locationsObject as |lul|}}
{{input type='checkbox' checked=lul.checked}}
{{lul.name}} {{lul.checked}}<br>
{{/each}}
<br>
<br>
{{#each checked as |lul|}}
{{lul}}<br>
{{/each}}
{
"version": "0.10.5",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.8.0",
"ember-data": "2.8.0",
"ember-template-compiler": "2.8.0",
"ember-testing": "2.8.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment