鍍金池/ 問答/HTML/ react.js中steps組件的這段代碼是什么意思呢?

react.js中steps組件的這段代碼是什么意思呢?

react.js中steps組件的這段代碼是什么意思呢?

<Steps progressDot current={state ? state[0] ? state[0] : null : null}
          status={this.checkStatus(state ? state[1] ? state[1] : null : null)}>
       ......   
</Steps>
回答
編輯回答
久愛她

三元控制符,防止出現(xiàn)空值。例如data = [],直接取data[0]豈不是就undefined了

2017年2月18日 08:33
編輯回答
幼梔

大概是這個意思吧

state && state[0] ? state[0] : null
2017年2月27日 14:24
編輯回答
吢涼

相當(dāng)于:
state ? (state[0] ? state[0] : null) : null
MDN有很好的解釋。
重要一點是雖然條件運(yùn)算符是右結(jié)合的,但是它的求值順序卻是從左向右

2018年6月3日 22:51
編輯回答
局外人
if (state){
    if (state[0]){
        return state[0]
    } else {
        return null
    }
} else {
    return null
}
2017年11月28日 04:13