coderenaissance / knockout.viewmodel

The knockout viewmodel plugin is the fastest, smallest, cleanest, most flexible way to create a knockout viewmodel.
http://coderenaissance.github.com/knockout.viewmodel
105 stars 27 forks source link

Add key to child array #45

Closed fedfigca closed 11 years ago

fedfigca commented 11 years ago

if my model is something like

var model = {parents: [ {id: 1, prop1: "true", children: [{id: 1, location:"somewhere"}, {id: 2, location:"somewhere else"}], {id: 2, prop1: "false", children[{id: 1, location:"anywhere"}] };

I can setup arrayChildId to parents id, and then the updateFromModel will correctly update the prop1, but the children array will get completely overwritten with the same data and properties like visible or selected get back to default, is there a way to tell the model that children.id is also a key?

fedfigca commented 11 years ago

I got some insight from the knockoutjs freenode channel, it is done with this option

arrayChildId: { "{root}.parents": "id", "{root}.parents[i].children": "id" }

I might only suggest that the documentation get's a little more clear about it, but thanks a lot for a great plugin.