在 IE9 中使用敲除 (2.1.0) 和敲除映射 (2.1.2) 出现了一些谜团。由于某种原因,对象的数组索引变成了父对象。例如:
ko.mapping.toJSON(attachments);
在 Chrome 中生成如下所示的内容:
{
"UserID": 432,
"Attachments": [{
"AttachmentID": 2,
"OwnerID": 321,
"DisplayName": "sample.pdf",
"Description": "desc",
"PostDate": "2012-06-01T09:24:43.817"
}, {
"AttachmentID": 3,
"OwnerID": 432,
"DisplayName": "sample3.pdf",
"Description": "desc",
"PostDate": "2012-06-05T14:01:00.693"
}, {
"AttachmentID": 4,
"OwnerID": 543,
"DisplayName": "sample2.pdf",
"Description": "desc",
"PostDate": "2012-06-05T14:01:49.18"
}]
}
...但在 IE9 中,会产生如下内容:
{
"UserID": 432,
"Attachments": {
"0": {
"AttachmentID": 2,
"OwnerID": 321,
"DisplayName": "sample.pdf",
"Description": "desc",
"PostDate": "2012-06-01T09:24:43.817"
},
"1": {
"AttachmentID": 3,
"OwnerID": 432,
"DisplayName": "sample3.pdf",
"Description": "desc",
"PostDate": "2012-06-05T14:01:00.693"
},
"2": {
"AttachmentID": 4,
"OwnerID": 543,
"DisplayName": "sample2.pdf",
"Description": "desc",
"PostDate": "2012-06-05T14:01:49.18"
}
}
}
这打破了我的淘汰赛绑定,因为模板期望附件是一阶数组。
有趣的是,json2 的 stringify 在我尝试过的每个浏览器中都会返回第一个输出(这是我所期望的)。
有没有人见过这种行为?关于如何纠正它的任何想法?