knockout.js - knockout.mapping, IE9 and serialization -
a bit of mystery has cropped using knockout (2.1.0) , knockout mapping (2.1.2) in ie9. reason, array indices of objects turned parent objects. example:
ko.mapping.tojson(attachments); produces looks in 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" }] } ... in ie9, produces this:
{ "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" } } } this breaks knockout bindings because template expecting attachments first-order array.
interestingly, json2's stringify returns first output (which i'd expect) in every browser i've tried.
has seen behavior before? ideas on how correct it?
the short version didn't find answer problem, did find workaround. isn't pretty. if override json object , force use json3 using delete window.json;, stringify hocus pocus this:
var jsonstring = json.stringify(objtobind); var reconstitutedobject = ko.utils.parsejson(jsonstring); ... create mapping reconstituted object , bind reconstituted object, container seems gone. suggests me there in array definition being interpreted container, after poking around in guts of main project, sniffing network traffic, , trying drill down how server responds, i'm coming short.
Comments
Post a Comment