-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 –