Des*_*xia 0 javascript conditional-operator reactjs
本质上我有以下问题:
if condition A & B are true ->. do thing A
if only condition A is true -> do thing B
else -> do thing C
Run Code Online (Sandbox Code Playgroud)
我试过这个:
const myThing = conditionA ? conditionB ? thingA :
conditionA ? thingB : thingC;
Run Code Online (Sandbox Code Playgroud)
它不喜欢这种语法,但我不确定它有什么问题。
const myThing = (conditionA && conditionB) ? thingA : (conditionA) ? thingB : thingC;
Run Code Online (Sandbox Code Playgroud)
与以下相同:
if(conditionA && conditionB){
thingA
}
else if(conditionA){
thingB
} else {
thingC
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4767 次 |
| 最近记录: |