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