我正在製作一個應用程序,其中有兩個下拉列表和一個文本框。有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自己填寫的帳戶語句文本框應顯示帳戶的陳述和如果贖回仿真然後仿真的硬拷貝。
我們可以幫助你。但是,我們首先需要一些東西。首先,我們需要您嘗試發佈的代碼在您的問題 –
Callum Linington中發佈,請檢查詳細信息,這可能有助於 – Dss
您不包含任何HTML文本字段。它是否具有「價值」綁定? –