-1
我有一個json文件,我正在通過一些服務獲取,然後在下拉列表中填充它。第一個下拉列表是正確填充的銀行名稱,但對於第二個和第三個下拉列表,我想填充城市和分行名稱不起作用。它僅填充第一家銀行的城市名稱和分行的相同名稱。 我已經加入其中,我用的是邏輯根據之前的下拉選擇值創建下拉
bankdetails.json
{
"banks": {
"SBI": {
"cities": {
"Bangalore": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
},"Hyderabad": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
}
}
},
"CBI": {
"cities": {
"pune": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
},"chennai": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
}
}
},
"HDFC": {
"cities": {
"Bangalore": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
},"Hyderabad": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
}
}
},
"BOI": {
"cities": {
"Bangalore": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
},"Hyderabad": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
}
}
},
"IDFC": {
"cities": {
"Bangalore": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
},"Hyderabad": {
"branches": {
"rrnamgar1": {
"ifsc" : "SBIN100000"
},
"rrnamgar2": {
"ifsc" : "SBIN100001"
}
}
}
}
}
}
}
component.ts
ngOnInit(){
this.banks = this.modalservice.returnBankList();
this.cities = this.banks[Object.keys(this.banks)[0]];
this.citiesname = this.cities[Object.keys(this.cities)[0]];
this.branches = this.citiesname[Object.keys(this.citiesname)[0]];
this.branchnames = this.branches[Object.keys(this.branches)[0]];
}
firstDropDownChanged(val: any) {
let obj = Object.keys(this.banks);
console.log(obj, val);
if (obj != null && val !== -1) {
this.city = Object.keys(this.cities["cities"]);
console.log("cities are " + this.city);
}
}
secondDropDownChanged(val: any) {
let obj = this.city;
console.log(val, obj);
if (!obj) return;
if (obj != null && val !== -1) {
this.branch = Object.keys(this.branches["branches"]);
}
嗨AJT_82。當我運行代碼時,您提示我在控制檯中出現了錯誤。 –
錯誤類型錯誤:無法在IDFCModalComponent.webpackJsonp .../../../../src/app/payment/modal/modal中將函數關鍵字() 上的undefined或null轉換爲對象 。 component.ts.IDFCModalComponent.transform(modal.component.ts:60) at IDFCModalComponent.webpackJsonp .../../../../src/app/payment/modal/modal.component.ts .IDFCModalComponent.ngOnInit(modal.component.ts:45) –
當我在變換方法中安慰value字段時,它給了我undefined –