How knockout ko.mapping.fromJs() handles the $ref nodes in Json

北城以北 提交于 2019-12-11 21:22:36

问题


The Json which came from the server contains some refs like this:

[
    {
        id:"1",
        name:"Mehran",
        supervisor:
        {
            id:"2",
            name: "Ayaz",
            supervisor: null
        }
    },
    {
        id:"3",
        name:"Ramin",
        supervisor: {$ref="1"}
    }
]

How does knockout mapping's fromJS or fromJson interpret this?


回答1:


JSON in your example is invalid. It is unexpected token {$ref="1"}.
Argument for fromJS function should be the valid JSON
and argument for function fromJson should be a string representation of valid JSON value.

Knockout will throw exeption in both cases. You should pass full object instead of reference



来源:https://stackoverflow.com/questions/18799385/how-knockout-ko-mapping-fromjs-handles-the-ref-nodes-in-json

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