简体   繁体   中英

Knockout mapping for nested json

I was trying to create a json schema viewer and editor. I need to show the dynamically generated nested json as nested table and must be able to edit them or add new. for that I was trying to map a nested json to knockout observable and to show them as a nested table

JSBin sample

But I failed to map it can anyone help me map it correctly and help me arrange the child tables as next 'tr'.

I'm not getting any error but the values are not displayed.

The code is absolutely not clean, but it seems to work: http://jsfiddle.net/ezg5U/

Basically, I track the path within the json data and dynamically set KO bindings like

data-bind="'text: values()[0]._values()[1].key'"

Also the textarea elements have the "value: " binding, thus storing the updated data in the view model.

The DIV below the table is updated automatically and shows the value of the nested key: vm.values()[0]._values()[0].key() - so you can see that the model is actually updated when a user changes the value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM