Last active
August 16, 2017 00:36
-
-
Save carlbennettnz/1a7c347fe5fe0a5a7f48b1e881a7cd34 to your computer and use it in GitHub Desktop.
Tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
tagName: 'ul' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const Item = Ember.Object.extend({ | |
isSelected: Ember.computed('_isSelected', 'children.@each.isSelected', { | |
get() { | |
return this.get('_isSelected') || | |
this.get('children').findBy('isSelected') != null; | |
}, | |
set(key, value) { | |
value = Boolean(value); | |
const update = (item) => { | |
if (item.get('children.length') === 0) { | |
item.set('_isSelected', value); | |
} else { | |
item.get('children').forEach(update); | |
} | |
} | |
update(this); | |
return value; | |
} | |
}), | |
_isSelected: false | |
}); | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
tree: [ | |
Item.create({ name: 'One', children: [ | |
Item.create({ name: 'One One', children: [] }), | |
Item.create({ name: 'One Two', children: [] }), | |
Item.create({ name: 'One Three', children: [] }), | |
Item.create({ name: 'One Four', children: [] }) | |
]}), | |
Item.create({ name: 'Two', children: [ | |
Item.create({ name: 'Two One', children: [] }), | |
Item.create({ name: 'Two Two', children: [] }), | |
Item.create({ name: 'Two Three', children: [] }), | |
Item.create({ name: 'Two Four', children: [] }) | |
]}) | |
] | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"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.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment