I have an Ember component that takes in an array as it's content and for each item renders a checkbox if it's an object or a new nested instance if it's an array.
The component needs to be able to bind data both to the first set of items in the root array and all the nested items. I though of using computed properties and observers but as Ember states You cannot use nested forms like [email protected] or [email protected][email protected].
Any idea how this can be achieved?
Component:
<dl class="selection-list">
{{#each content}}
<dd>
{{#isArray this}}
{{selection-list content=this}}
{{else}}
<label class="checkbox">
{{input type="checkbox" checked=selected disabled=disabled}}
{{label}}
</label>
{{#isArray children}}
{{selection-list content=children}}
{{/isArray}}
{{/isArray}}
</dd>
{{/each}}
</dl>
Model:
App.ApplicationRoute = Ember.Route.extend({
model: function () {
return {
items: [
{
label: '1'
},
{
label: '2',
children: [
{
label: '2.1'
},
{
label: '2.2',
children: [
{
label: '2.2.1'
},
{
label: '2.2.2'
},
{
label: '2.2.3'
}
]
}
]
},
{
label: '3'
},
{
label: '4'
}
]
};
}
});
Use of binding:
App.ApplicationController = Ember.ObjectController.extend({
selectionCount: function () {
return this.get('items').filterBy('selected').length;
}.property('[email protected]')
});