react中根据后台值动态配置

业务中我们要实现对应的数据是1是男,2是女,这就要根据键来进行动态匹配,通常后台来给你一个1或者2,你来进行匹配,这样的数据一般在表格中比较常见。

<Card title="Mock-单选" style={{margin:'10px 0'}}>
           < Table bordered columns = {
             columns
           }
           rowSelection = {
             rowSelection
           }
           pagination = {
             false
           }
           dataSource = {
             this.state.dataSource2
           }
          }
          >
           </Table>
        </Card>
const columns = [
{
title:'序号',
key:'id',
dataIndex:'id'
},
{
title: '姓名',
dataIndex: 'userName',
key: 'userName',
}, {
title: '年龄',
dataIndex: 'sex',
key: 'sex',
render(sex){
return sex === 1 ? '男' : '女'
}
},{
title:'状态',
key:'state',
dataIndex:'state',
render(state){
let config = {
'1':'加油更好',
'2':'升值加薪',
'3':'新春快乐',
'4':'勇往直前',
'5':'希望明年会更好'
}
return config[state]
}
},{
title:'爱好',
key: 'interest',
dataIndex: 'interest',
render(love){
let config = {
'1': '游泳',
'2': '打篮球',
'3': '踢足球',
'4': '跑步',
'5': '爬山',
'6': '骑行',
'7': '桌球',
'8': '麦霸'
}
return config[love]
}
}, {
title:'生日',
key: 'birthday',
dataIndex: 'birthday'
},{
title: '住址',
dataIndex: 'adress',
key: 'adress',
},{
title:'早起时间',
dataIndex: 'time',
key:'time'
}];

  这时候性别和地址是动态的,后台可能会给你一个1,2来匹配性别

猜你喜欢

转载自www.cnblogs.com/smdb/p/10364175.html
今日推荐