【发布时间】:2020-12-06 08:36:11
【问题描述】:
您好,如果.. 有没有办法创建地图并编写更好的代码,我想根据这些创建地图?
findViewDetailPolicy(policy) {
if (policy['displayInfo']['displayTypeDetail']['displayType'] === 'STANDARD') {
this.path = this.policyPathDetailStandard;
this.router.navigate([this.path]);
}
if (policy['displayInfo']['displayTypeDetail']['displayType'] === 'PACCHETTO') {
this.path = this.policyPathDetailModulare;
this.router.navigate([this.path]);
}
if (policy['displayInfo']['displayTypeDetail']['displayType'] === 'SAVING') {
this.path = this.policyPathDetailSaving;
this.router.navigate([this.path]);
}
if (policy['displayInfo']['displayTypeDetail']['displayType'] === 'CQ') {
this.path = this.policyPathDetailCq;
this.router.navigate([this.path]);
}
if (policy['displayInfo']['displayTypeDetail']['displayType'] === 'COLLETTIVA') {
this.path = this.policyPathDetailCollective;
this.router.navigate([this.path]);
}
}
【问题讨论】:
-
switch case 可以完成这项工作。检查文档。 w3schools.com/js/js_switch.asp
-
不是映射,但更好的方法是尝试将
policy['displayInfo']['displayTypeDetail']['displayType']放入变量中并以更好的方式编写这些条件
标签: javascript arrays json angular typescript