JSX中写 switch case 进行判断

场景:根据后端返回的数据进行多条件渲染,三元表达式已不能满足条件。

代码:

 <span>
                {(() => {
                  switch (record.generalRuleInfos[0]?.factors[0]?.baseDataKey) {
                    case 'poiType':
                      return '门店类型'
                    case 'roleId':
                      return '干系人角色ID'
                    case 'goodType':
                      return '商品类型'
                    default:
                      return null
                  }
                })()}
              </span>

 

posted @ 2020-11-20 16:09  liaoing  阅读(255)  评论(0编辑  收藏  举报