如何链接三元运算符?

How to chain Ternary Operators?

我在多个条件下根据三元运算符中的值显示不同的数据:

我有这个,

 [attr.data-pendo]="linkedItemType === LinkedItemType.Prospect ? 'pendo-prospects' : 'pendo-loans'"

我还需要添加1个条件,

所以就像:

 if linkedItemType === LinkedItemType.Prospect then 'pendo-prospects' 
 if linkedItemType === LinkedItemType.Loan then 'pendo-loan' 
 else 'pendo-task'

如何用三进制实现这个?

是这样的:

linkedItemType == LinkedItemType.Prospect ? "pendo-prospects" : linkedItemType == LinkedItemType.Loan ? "pendo-loan" : "pendo-task";

或者,为了便于阅读,将同一内容分成不同的行:

linkedItemType == LinkedItemType.Prospect ? "pendo-prospects" 
: linkedItemType == LinkedItemType.Loan ? "pendo-loan" 
: "pendo-task";