일부 서비스를 받고 나서 드롭 다운에 채우는 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. 변경 사항이있는 코드를 실행했을 때 콘솔에서 오류가 발생했습니다. –
오류 TypeError : IDFCModalComponent.webpackJsonp .../../../../src/app/payment/modal/modal에있는 Function.keys () 에서 정의되지 않거나 null 인 객체 으로 변환 할 수 없습니다. IDFCModalComponent.webpackJsonp .../../../../../src/app/payment/modal/modal.component.ts의 component.ts.IDFCModalComponent.transform (modal.component.ts : 60) .IDFCModalComponent.ngOnInit (modal.component.ts : 45) –
변환 메서드에서 값 필드를 consoling 할 때 정의되지 않은 값이 부여됩니다. –