Knockout mapping for nested json

家住魔仙堡 提交于 2020-01-05 05:57:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18008897/knockout-mapping-for-nested-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!