嵌套json的淘汰赛映射 [英] Knockout mapping for nested json

查看:75
本文介绍了嵌套json的淘汰赛映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个json模式查看器和编辑器.我需要将动态生成的嵌套json显示为嵌套表,并且必须能够对其进行编辑或添加新的嵌套json.为此,我试图将嵌套的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示例

但是我无法映射它,任何人都可以帮助我正确映射它,并帮助我将子表安排为下一个"tr".

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/

基本上,我跟踪json数据中的路径并动态设置KO绑定,例如

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

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

textarea元素还具有"value:"绑定,因此将更新的数据存储在视图模型中.

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

表下方的DIV自动更新,并显示嵌套键的值:vm.values()[0] ._ values()[0] .key()-这样您就可以看到模型实际上已更新当用户更改值时.

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.

这篇关于嵌套json的淘汰赛映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆