Javascript 如何向react表组件添加ID?
我正在尝试向我创建的一组react表添加一个唯一的id。 我创建了一个使用react表的自定义组件 我已经尝试将id道具添加到标记中,但这不起作用,我猜这是因为库中没有定义id道具Javascript 如何向react表组件添加ID?,javascript,reactjs,react-table,Javascript,Reactjs,React Table,我正在尝试向我创建的一组react表添加一个唯一的id。 我创建了一个使用react表的自定义组件 我已经尝试将id道具添加到标记中,但这不起作用,我猜这是因为库中没有定义id道具 return <ReactTable data={props.data} columns={columns} showPagination={false} minRows={5} style={{height :"400px"}} id='someId'/>; 返回; 我本以为这会将id属性添加到re
return <ReactTable data={props.data} columns={columns} showPagination={false} minRows={5} style={{height :"400px"}} id='someId'/>;
返回;
我本以为这会将id属性添加到react表库创建的div中,但事实并非如此。看起来react表是通过reactable元素上的
getProps
属性来处理这一问题的,它接受一个回调,该回调应该返回您的自定义属性。在render()函数中尝试以下代码段
const customProps = { id: 'my-table-id' };
return (
<ReactTable
data={props.data}
columns={columns}
showPagination={false}
minRows={5}
style={{height :"400px"}}
getProps={() => customProps}
/>
);
constcustomprops={id:'my table id'};
返回(
customProps}
/>
);
将元素包装成一个,并给它一个id。return
问题是,为什么需要id?如果你想访问它,你应该使用ref.Automation团队要求的react方式来访问它,正因为如此,谢谢-使用本文左上角的向上箭头和复选标记,随时向上投票并接受。欢迎使用堆栈溢出:)我已经这样做了:)我的upvote没有显示,因为我太新了,但我也选中了它。再次感谢!