0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ALSO: The coderenaissance.github.io/knockout.viewmodel plugin allows this to be done dynamically to wrap\unwrap any POJO in observables dynamically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.