简体   繁体   English

剔除observableArray访问

[英]knockout observableArray access

How can I send OptionsServer to Server correctly ? 如何将OptionsServer正确发送到服务器? 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
}),

This way it works : 这样工作:

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

See fiddle 见小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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