I have an object that contains a dictionary and I'm trying to figure out how to set this up with Knockout and have been making very little progress.
var jsonViewModelText = { "User": { "IsDisabled": false, "Id": "2343243", "IsActive": true, "LockedOutUntil": null, "UnlockedUntil": null, "Claims": { "key0": "value0", "key1": "value1", "key2": "value2" }, "ExternalId": "afdsfdsa", "FirstName": "Chris", "LastName": "Marisic", "OracleId": "FML", "UserName": "chrism@.com", "GlobalAdmin": true }, "Flat1": null, "Flat2": "bob" };
var jsonViewModel = ko.mapping.fromJS(jsonViewModelText);
ko.applyBindings(jsonViewModel);
When I inspect jsonViewModel.User.Claims I see that Claims gets transformed into what looks like a first class object that I would need to invoke something like jsonViewModel.User.Claims.key0() to read the value from it. Being that this is a dictionary I implicitly have no knowledge of what the key names would be at runtime. So I'm not really sure how I could write a template for this.
When I was originally working with knockout and testing some manual objects I was creating I was able to get this template to work
<script id="claimsTemplate" type="text/html">
{{each(index, claim) User.Claims}}
<div>
<label >
Key:</label>
<input type="text" value= "${ claim.key }" />
</div>
<div>
<label >
Value:</label>
<input type="text" value= "${ claim.value }" />
</div>
{{/each}}
</script>
But that worked when I was creating a true array by hand with array items being objects with key and value properties. I'm not sure how I would work with what Knockout Mapper creates from my json, also I wonder about the implications of posting that model back to
ASP.NET MVC3, I have no idea what the model binder will see there.