Reputation: 10788
I am attempting to load a ViewModel property with mapped data on initial page load and then at a later time, append new JSON data to this mapped property. Following the docs here (http://knockoutjs.com/documentation/plugins-mapping.html), it would appear that all I need to do is call ko.mapping.fromJS(data, {}, someObject);
to combine data
and someObject
. Can someone tell me why this would not work? Please see fiddle example below:
I would expect
{
"Foo": [
{
"Property": "Value1"
}
]
}
to become
{
"Foo": [
{
"Property": "Value1"
},
{
"Property": "Value2"
}
]
}
Upvotes: 0
Views: 42
Reputation: 136174
You should push
an item to the observable array obtained from the first call to fromJS
. So change this line:
ko.mapping.fromJS(data2, {}, self.Foo);
to this
self.Foo.push(ko.mapping.fromJS(data2));
Live example: http://jsfiddle.net/m4uKe/2/
Upvotes: 1