I'm trying to do some complex binding with knockout (at least for a newbie like me).
Consider the following data:
var originalData = {
id: 1,
name: "Main",
children: [ { id: 2, name: "bob", children: []}, { id: 3, name: "ted", children: [{id: 5, name:"albert"}, {id: 9, name: "fred"}]} ],
selectedChild: { id: 2, name: "bob" }
};
<table>
<tr>
<td data-bind="text: name"></td>
</tr>
<tr data-bind="if: children().length > 0">
<td>
<select data-bind="options: children,
optionsText: function(item){
return item.name;
},
optionsCaption: 'Choose...'"></select>
</td>
</tr>
Ok, that was the easy part.
The hard part, is that whenever an item is selected in the list, if this item has children then a new select box should appear underneath. Its datasource would be the children of the selected item in the first select box. Of course, it could continue on with any level of deepness.
How should I solve this problem with knockout ?
I've put together a sample of what I have so far on jsfiddle: http://jsfiddle.net/graphicsxp/qXZjM/