Is it possible to create a recursive template only with knockout js?
I have a knockout object:
function FormElementNode(children, text, value) {
v
This post was a great help to me. I am always finding new ways to use knockout. I just wanted to add one useful modification which is doing exactly what nemesv proposed only using the ko.mapping plugin.
//Nested javascript object:
var formElementNode = {
children: [{
children: [],
text: 'Child1',
value: 'Value1'
}, {
children: [{
children: [{
children: [],
text: 'Child2.1.1',
value: 'Value2.1.1'
}],
text: 'Child2.1',
value: 'Value2.1'
}],
text: 'Child2',
value: 'Value2'
}, {
children: [],
text: 'Child3',
value: 'Value3'
}],
text: 'Main',
value: 'MainValue'
};
//Use ko.mapping to generate viewModel:
var viewModel = ko.mapping.fromJS(formElementNode);
ko.applyBindings(viewModel);
As demonstrated in this jsFiddle.