Flat Model to Tree ViewModel

47 views
Skip to first unread message

Ryan Leach

unread,
Apr 11, 2017, 2:00:44 AM4/11/17
to KnockoutJS
I've inherited a codebase that is currently using ko.mapping in order to parse an array of plain java objects into knockout view models.

The project is a html form builder, that has been retrofitted from a flat absolutely positioned flat collection of form pieces, to a responsive tree based editor.

However the backend still looks like the original flat collection of view models / data.

I'd like the view model to be recursive, but the underlying model / storage to be flat, as it means no changes will be required to the backend.

Does anyone have any pointers, tips, or resources that already exist that might help?

Specifically:
Are there any tips on using ko.mapping in conjunction with manually specified view models?

Will having a "large" (hundred or so) view models on a page slow things down massively? ( I suspect they already have this and don't realize)

What's the best method to throttle changes or defer updates, so that multiple observers changing on a single object can be batched into a single ajax request.

A simple analog of the data looks as follows.
[
{
id:2,
name: "Div",
parent: 1,
prop1...2...3...
},
{
id:3,
name: "Date",
parent: 2,
prop1...2...3...
},
{
id:4,
name: "First Name",
parent: 2,
prop1...2...3...
},
{
id:1,
name: "Root",
parent: null,
prop1...2...3...
}
]

Thanks to any responses in advanced.

--
Ryan Leach
Reply all
Reply to author
Forward
0 new messages