问题
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