Created
October 15, 2018 22:23
-
-
Save luxzeitlos/f7965319bd2e061c5f6bab2a94807dda to your computer and use it in GitHub Desktop.
New Twiddle
This file contains hidden or 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({ | |
selected: [], | |
actions: { | |
select(id) { | |
// this is a *bit* ugly because the child object has no relation to the parent. So there is actually not a *easy* way to get the right parent or to know if its a child or a parent. | |
// so this code basically gives us the array of elements that are valid selections. | |
// if the clicked element is a parent thats all parents (so this.data) | |
// if the clicked element is a child thats all children of the parent | |
const group = this.data.find(x => x.id === id) | |
? this.data | |
: this.data.find(p => p.children.find(c => c.id === id)).children; | |
const validIds = group.map(x => x.id); | |
this.set('selected', [ | |
id, | |
...this.selected.filter(s => validIds.includes(s)), | |
]); | |
} | |
} | |
}); |
This file contains hidden or 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 function includes([elem, arr]/*, hash*/) { | |
return arr.includes(elem); | |
} | |
export default Ember.Helper.helper(includes); |
This file contains hidden or 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.Route.extend({ | |
model() { | |
return [{ | |
id: 1, | |
label: 'burger', | |
children: [{ | |
id: 3, | |
label: 'tomato', | |
}, { | |
id: 4, | |
label: 'lettus', | |
}, { | |
id: 5, | |
label: 'pickle', | |
}] | |
}, { | |
id: 2, | |
label: 'kebab', | |
children: [{ | |
id: 6, | |
label: 'ketchup', | |
}, { | |
id: 7, | |
label: 'chilli', | |
}] | |
}, { | |
id: 8, | |
label: 'coffee maker', | |
children: [{ | |
id: 9, | |
label: 'filter', | |
}, { | |
id: 10, | |
label: 'grounds', | |
}] | |
}]; | |
} | |
}); |
This file contains hidden or 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.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