简体   繁体   中英

Knockout set observable array in array

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM