Skip to content

Instantly share code, notes, and snippets.

@onlymejosh
Forked from vitch/application.controller.js
Last active November 3, 2015 22:18
Show Gist options
  • Save onlymejosh/7dcb1a0d38b218bc4fe4 to your computer and use it in GitHub Desktop.
Save onlymejosh/7dcb1a0d38b218bc4fe4 to your computer and use it in GitHub Desktop.
yielding actions
import Ember from 'ember';
const { Controller, computed } = Ember;
export default Controller.extend({
totalItems: 3,
items: computed(function() {
return [
{id: 1, title:'1'},
{id: 2, title:'2'},
{id: 3, title:'3'},
];
})
});
<h1>Select all component?</h1>
<br>
<br>
{{#selectable-list displayItems=items numTotalItems=totalItems as |onCheckboxChange|}}
{{#each items as |item|}}
<label>
{{input type="checkbox" change=(action onCheckboxChange item)}}
Item {{item.title}}
</label>
{{/each}}
{{/selectable-list}}
import Ember from 'ember';
const { Component } = Ember;
const ALL = Symbol();
const ALL_EXCEPT = Symbol();
const SOME = Symbol();
const NONE = Symbol();
export default Component.extend({
// Server total of items, this can either be virtual or actual total
numTotalItems: 0,
// Items which are currently displayed
displayItems: [],
selectedItemIds: [],
delectedItemIds: [],
selectionState: NONE,
actions: {
onCheckboxChange(model, event) {
console.log(model, event.target.checked);
}
}
});
{{yield (action 'onCheckboxChange')}}
{
"version": "0.4.16",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js",
"ember": "2.0.2",
"ember-template-compiler": "2.0.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment