0

我正在製作一個應用程序,其中有兩個下拉列表和一個文本框。有JSON數據我想要綁定。我能夠綁定下拉列表,即在第一次下拉第二下降是改變。問題是我不能綁定數據與文本字段。可以任何身體幫助我嗎?綁定數據與下拉列表

供參考的代碼是HTML

<select data-bind="options: financialYear,value: animalTypea, optionsText: 'description',optionsValue: 'value'"> 
</select> 
<select data-bind="options: animalsForType,value: animalType, optionsText: 'description',optionsValue: 'value'"></select> 


<input type="text" data-bind="value: subject" /> 

和JS代碼是

response.invocationResult.customerRequestMasterDetailBeans.forEach(function (item1) { 
    if(item1.key == "") { 
    self.financialYear.push(item1); 
    } 
}); 

self.financialYear = ko.observableArray([]); 
self.animalTypea = ko.observable(); 

self.financialYeara = ko.observableArray([]); 
self.animalTypea = ko.observable(); 

self.animalType = ko.observable(); 

self.subject = ko.observable(); 

self.animalsForType = ko.computed(function() { 
    var selectedType = self.animalTypea(); 

    return !selectedType ? [] : response.invocationResult.customerRequestMasterDetailBeans.filter(function (data) { 
    return data.key == selectedType; 
    }); 
}); 

self.subject = ko.computed(function() { 
    var selectedType = self.animalType(); 
    return !selectedType ? [] : response.invocationResult.customerRequestMasterDetailBeans.filter(function (data) { 

    return data.subjectMessage == selectedType; 
    }); 

}); 

和用於參考的JSON是

{ 
    "customerRequestMasterDetailBeans": [ 
     { 
      "requestMessage": "", 
      "subjectMessage": "", 
      "description": "DocumentRequest", 
      "value": "DR", 
      "formatMessage": "", 
      "serviceCharge": "", 
      "key": "" 
     }, 
     { 
      "requestMessage": "AservicechargeofRs50.00perstatementrequestwillbeapplied.Doyouwanttoproceed?", 
      "subjectMessage": "HardcopyofStatementofAccount", 
      "description": "StatementofAccount", 
      "value": "SDR", 
      "formatMessage": "PleasesendmeahardcopyofupdatedStatementofAccountatmyregisteredaddress.", 
      "serviceCharge": "Rs50.00", 
      "key": "DR" 
     }, 
     { 
      "requestMessage": "AservicechargeofRs50.00perstatementrequestwillbeapplied.Doyouwanttoproceed?", 
      "subjectMessage": "HardcopyofForeclosureSimulation", 
      "description": "ForeclosureSimulation", 
      "value": "FCDR", 
      "formatMessage": "PleasesendmeahardcopyofupdatedForeclosureSimulationatmyregisteredaddress.", 
      "serviceCharge": "Rs50.00", 
      "key": "DR" 
     } 
    ] 
} 

其實我想顯示文檔請求在第一個下拉菜單中,第二個下拉菜單中的賬戶和止贖模擬報表下降。現在如果第二個下降d自己填寫的帳戶語句文本框應顯示帳戶的陳述和如果贖回仿真然後仿真的硬拷貝。

+0

我們可以幫助你。但是,我們首先需要一些東西。首先,我們需要您嘗試發佈的代碼在您的問題 –

+0

Callum Linington中發佈,請檢查詳細信息,這可能有助於 – Dss

+0

您不包含任何HTML文本字段。它是否具有「價值」綁定? –

回答

0

從我所看到的,你的問題是由於輸入的綁定到計算值,這應取決於視圖模型的價值,不應該是編輯。

我會建議你使用或文本結合,而不是結合和使用範圍的DIV而不是輸入作爲http://knockoutjs.com/documentation/computedObservables.html解釋。

<span data-bind="text: subject"></span> 

如果你真的希望能夠編輯主題在輸入節點的值,(你可能希望能夠通過輸入不同的東西在這裏更改選擇),你可以使用一個觀察到告訴淘汰賽當你在那裏輸入一個值時你想要做什麼(在http://knockoutjs.com/documentation/computed-writable.html的很好的解釋)。