0

How can I send OptionsServer to Server correctly ? Cause I'm trying to send values from checked Checkbox to server.

My code:

var viewModel = {};

viewModel.ui = {};

viewModel.ui.FlashbackReport = {
    ChoosenEmails : ko.observableArray(),
    ChoosenOptions : ko.observableArray(),
    OptionsServer :  ko.observableArray(),
    Options : ko.observableArray([ "New Contacts", "Updated Contacts","Verified Contacts" ]),
    OptionsToSend: ko.computed({
        read : function () {
            var viewModelShortcut= viewModel.ui.FlashbackReport;
            if (viewModelShortcut.ChoosenOptions()=="New Contacts")
                viewModelShortcut.OptionsServer.push('NEW');  
             else if (viewModelShortcut.ChoosenOptions()=="Updated Contacts")    
                 viewModelShortcut.OptionsServer.push('BETTER'); 
             else if (viewModelShortcut.ChoosenOptions()=="Verified Contacts")  
                 viewModelShortcut.OptionsServer.push('NOT_BETTER');  
        /*   else if (viewModelShortcut.ChoosenOptions()[0]=="New Contacts" 
                     && viewModelShortcut.ChoosenOptions()[1]=="Updated Contacts" 
                     && viewModelShortcut.ChoosenOptions()[2]=="Verified Contacts")
                 viewModelShortcut.OptionsServer.push('NEW','BETTER','NOT_BETTER'); 
        */      
},
    deferEvaluation: true
}),

1 Answer 1

1

This way it works :

OptionsToSend: ko.computed({
    read : function () {
          console.info(viewModel.ui.Report.Options()[0]);
    },
    deferEvaluation: true
})

See fiddle

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

2 Comments

can u help me again for my Options to send for server ? I have 3 checkboxes : New contacts, updated contacts, verified contacts And I would like to send the correct values to my server but if the user check, uncheck checkbox my OptionsServer array is not edited...
I will be glad to help you again. But, I think this is another question. In order to help people that are facing the same problem, consider to close this question and create anther one.

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.