const {
log
} = console
let a = 2
// let b = 2
// let c = 3
// if (a == 1) {
// log(1)
// } else if (a == 2) {
// log(2)
// } else {
// log(3)
// }
a==1?log(1):a==2?log(2):log(3)
在jsx中的用法:
{
currentDetail.ButtonStatus=='ENROL'?
<Button className={styles.enrolBtn} onClick={handleEnrol}>{intl.formatMessage({ id: 'courseDetail.Enrol' })}</Button>
:currentDetail.ButtonStatus=='Not_ENROL'?<Tooltip title={currentDetail.Remark}><Button className={styles.notEnrolBtn} disabled>{intl.formatMessage({ id: 'courseDetail.Enrol' })}</Button></Tooltip>
:currentDetail.ButtonStatus=='CANCEL'?<Button className={styles.enrolBtn} onClick={handleEnrol}>{intl.formatMessage({ id: 'courseDetail.comfirmCancel' })}</Button>
:currentDetail.ButtonStatus=='Not_CANCEL'?<Tooltip title={currentDetail.Remark}><Button className={styles.notEnrolBtn} disabled>{intl.formatMessage({ id: 'courseDetail.comfirmCancel' })}</Button></Tooltip>:null
}
<Modal title={!!currentDetail&¤tDetail.ButtonStatus=='ENROL'&&comfirmInfor&&comfirmInfor.StatusCode=='1001'||!!currentDetail&¤tDetail.ButtonComfirm=='Comfirm_Enrol'&&comfirmInfor&&comfirmInfor.StatusCode=='1001'?intl.formatMessage({ id: 'courseDetail.confirmInfo' }):!!currentDetail&¤tDetail.ButtonStatus=='ENROL'&&comfirmInfor&&comfirmInfor.StatusCode=='1002'||!!currentDetail&¤tDetail.ButtonComfirm=='Comfirm_Enrol'&&comfirmInfor&&comfirmInfor.StatusCode=='1002'?intl.formatMessage({ id: 'courseDetail.confirmInfoWaitlisted' }):!!currentDetail&¤tDetail.ButtonStatus=='CANCEL'?intl.formatMessage({ id: 'courseDetail.confirmInfoCancel' }):null}
当时是三个titile公用一个弹窗,占位,取消,候补;waisted 候补弹窗的时候,我打算用三目,把最后的默认选项给候补弹窗;结果因为取值的原因没能实现。 最后linlin实现了。结果就是这串代码;区别除了 请求存值的原因以外;她最后用的null。 if else if esle;最后的null==三目的else; 我想,候补弹窗还是需要if 判断一下。else 默认还是null吧!