Using Knockout mapping for complex JSON

风流意气都作罢 提交于 2019-12-04 13:04:49

The mapping plugin is working as you expect. Your problem is simply that you are expecting the plugin to create observables at every level in the object. This is not how the plugin works. It will only create observables for "leaf" properties. So in your case $root.Results.highlighting is not created as an observable. The id properties on docs are however created as observables so the solution is.

$root.Results.highlighting[Id()]

I believe you may have been confused because one of your fiddles was assigning self.Results twice which made it appear to work one way when in fact the problem was being masked.

Here is the working version

http://jsfiddle.net/madcapnmckay/UaBKe/

Hope this helps.

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