html:<ng-container *ngIf="oCode_test1(table.oCode)'">
<span>{{aaa}}:</span></ng-container><ng-container *ngIf="oCode_test2(table.oCode)'">
<span>{{bbb}}:</span></ng-container><ng-container *ngIf="oCode_test3(table.oCode)'">
<span>{{ccc}}:</span></ng-container>ts: oCode_test1(oCode){ if(oCode == 'aa' || oCode == 'aa1st' || oCode == 'aah2' ||
oCode == 'aaq1' || oCode == 'aaq3' || oCode == 'aaq4'){ return true
} return false
}
oCode_test2(oCode){ if(oCode == 'qq' || oCode == 'qq1st' || oCode == 'qqh2' ||
oCode == 'qqq1' || oCode == 'qqq3' || oCode == 'qqq4'){ return true
} return false
}
oCode_test3(oCode){ if(oCode == 'ww' || oCode == 'ww1st' || oCode == 'wwh2' ||
oCode == 'wwq1' || oCode == 'wwq3' || oCode == 'wwq4'){ return true
} return false
}ts的部分,感觉重复性过高,该怎么优化,3个function有办法合并成一个吗?
2 回答
慕雪6442864
TA贡献1812条经验 获得超5个赞
public readonly testCaseOne = ['aa', 'aa1st', 'aah2', 'aaq1', 'aaq3', 'aaq4'];public oCode_test(oCode, testCase) { return testCase.includes(oCode); }
<ng-container *ngIf="oCode_test(table.oCode, testCaseOne)"> <span>{{aaa}}:</span></ng-container>
添加回答
举报
0/150
提交
取消