Alm*_*lma -3 c# conditional-operator
我根据多种条件下三元运算符中的值显示不同的数据:
我有这个,
[attr.data-pendo]="linkedItemType === LinkedItemType.Prospect ? 'pendo-prospects' : 'pendo-loans'"
Run Code Online (Sandbox Code Playgroud)
我还需要添加 1 个条件,
所以它就像:
if linkedItemType === LinkedItemType.Prospect then 'pendo-prospects'
if linkedItemType === LinkedItemType.Loan then 'pendo-loan'
else 'pendo-task'
Run Code Online (Sandbox Code Playgroud)
如何在三元中实现这个?
use*_*993 14
方法是这样的:
linkedItemType == LinkedItemType.Prospect ? "pendo-prospects" : linkedItemType == LinkedItemType.Loan ? "pendo-loan" : "pendo-task";
Run Code Online (Sandbox Code Playgroud)
或者,为了可读性,将同一内容分成不同的行:
linkedItemType == LinkedItemType.Prospect ? "pendo-prospects"
: linkedItemType == LinkedItemType.Loan ? "pendo-loan"
: "pendo-task";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10285 次 |
| 最近记录: |