Reactjs 如何在react表中为按钮动态添加值
我有一个react表(使用react表)组件,如下所示。在列状态下,我希望使用动态值渲染每个单元格中的按钮。我想从服务器数据中获取这些值 我基本上想要如下的东西:Reactjs 如何在react表中为按钮动态添加值,reactjs,Reactjs,我有一个react表(使用react表)组件,如下所示。在列状态下,我希望使用动态值渲染每个单元格中的按钮。我想从服务器数据中获取这些值 我基本上想要如下的东西: { //Header: 'Download', id: 'request_state', filterable: false, Cell: ({index}) => (<Button id={"approve_" + index} value={<Format
{
//Header: 'Download',
id: 'request_state',
filterable: false,
Cell: ({index}) =>
(<Button id={"approve_" + index}
value={<FormattedMessage id={"Approve_" + index} defaultMessage={data.request_state}}
fontSize={14}
minHeight={33}
minWidth={"100%"}
backgroundColor="transparent"
borderRadius={5}
icon={<Download size={13} color={'black'}></Download>}
onClick={() => this.handleDownloadDelivery(index)}
/>)
}
{
//标题:“下载”,
id:“请求状态”,
可过滤:false,
单元格:({index})=>
()
}
我解决了它,如下所示:
{
id: 'invite_accept',
filterable: false,
accessor: data => {
let output =[];
output = data.request_state;
if(output == 'invited') {
output = 'Accept Invitation'
}
return output;
},
Cell: props => <Button id={"Approve_" + props}
value={<FormattedMessage id={"Approve_" + props} defaultMessage={props.value}/>}
fontSize={14}
minHeight={33}
minWidth= {"100%"}
backgroundColor="transparent"
border={10}
borderRadius={5}
icon={<Eye size={14} color={'black'}></Eye>}
onClick={() => this.handleApproveOrRequestDelivery(props)}
/>
},
{
id:“邀请\接受”,
可过滤:false,
访问器:数据=>{
让输出=[];
输出=data.request\u状态;
如果(输出==‘已邀请’){
输出='接受邀请'
}
返回输出;
},
单元格:props=>this.handleApproveOrRequestDelivery(props)}
/>
},
{
//Header: 'Download',
id: 'request_state',
filterable: false,
Cell: ({index}) =>
(<Button id={"approve_" + index}
value={<FormattedMessage id={"Approve_" + index} defaultMessage={data.request_state}}
fontSize={14}
minHeight={33}
minWidth={"100%"}
backgroundColor="transparent"
borderRadius={5}
icon={<Download size={13} color={'black'}></Download>}
onClick={() => this.handleDownloadDelivery(index)}
/>)
}
{
id: 'invite_accept',
filterable: false,
accessor: data => {
let output =[];
output = data.request_state;
if(output == 'invited') {
output = 'Accept Invitation'
}
return output;
},
Cell: props => <Button id={"Approve_" + props}
value={<FormattedMessage id={"Approve_" + props} defaultMessage={props.value}/>}
fontSize={14}
minHeight={33}
minWidth= {"100%"}
backgroundColor="transparent"
border={10}
borderRadius={5}
icon={<Eye size={14} color={'black'}></Eye>}
onClick={() => this.handleApproveOrRequestDelivery(props)}
/>
},