2013-07-18 115 views
0

如何將OptionsServer正確發送到服務器?因爲我試圖將選中的複選框的值發送到服務器。knockout observableArray訪問

我的代碼:

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

這樣,它的工作原理:

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

See fiddle

+0

哦~~陸續嘗試的工作!謝謝 !! – user2587781

+0

@ user2587781不客氣 – Damien

+0

你能幫我再次選擇我的服務器嗎? 我有3個複選框:新的聯繫人,更新聯繫人,驗證接觸 我想正確的價值觀發送到我的服務器,但如果用戶檢查,取消選中複選框我OptionsServer陣列不是編輯... – user2587781