Reputation: 293
I have a small question about knockout.
I have made a viewmodel that looks like this (there are more subitems then Actions)
{
"PlatformSettings": [
{
"Actions": [
{
"Selected": false,
"Text": "None",
"Value": "None"
},
{
"Selected": true,
"Text": "Validation1",
"Value": "Validation1"
},
{
"Selected": true,
"Text": "Validation2",
"Value": "Validation2"
},
{
"Selected": true,
"Text": "Validation3",
"Value": "Validation3"
}
],
"Platform": {
"Id": "89",
"Description": "ONTWIKKELB"
}
},{
"Actions": [
{
"Selected": false,
"Text": "None",
"Value": "None"
},
{
"Selected": true,
"Text": "Validation1",
"Value": "Validation1"
},
{
"Selected": true,
"Text": "Validation2",
"Value": "Validation2"
},
{
"Selected": true,
"Text": "Validation3",
"Value": "Validation3"
}
],
"Platform": {
"Id": "89",
"Description": "ONTWIKKELB"
}
}
It works fine, but when i edit the checkboxes in my view and map them
self.Save = function(validate) {
var unmapped = ko.mapping.toJSON(self);
******
return false;
};
unmapped doesn't show the changes. And all the select values still show as on page load. I tried to make observable arrays, but the past 2 hours, but i can't figure it out.
Many thanks
Upvotes: 0
Views: 158
Reputation: 1890
Making the array observable will notify subscribers on add\remove. Making the "selected" property of each element observable will notify subscribers when it changes and allow 2 way binding.
So basically, make the selected property of each array element an observable too.
Upvotes: 1