我读了一些问题,我发现我可以在 MaterialTable 中设置“tableRef”并在第一时间设置检查状态,谢谢你
<MaterialTable
tableRef={this.tableRolesRef} //this.tableRolesRef=React.createRef();
columns={[
{title:"viewname",field:"viewname",sorting:false},
{title:"modelname",field:"modelname",sorting:false,cellStyle:{whiteSpace:'nowrap'}},
{title:"parentid",field:"parentid",sorting:false},
{title:"id",field:"id",sorting:false},
{title:"filename",field:"filename",sorting:false},
{title:"version",field:"version",sorting:false},
]}
actions={[
{
icon:'toggle_on',
tooltip:'open',
onClick:(event,rows)=>{console.log(rows,this.tableRef)}
}
]}
data={modules}
title="permission"
parentChildData={(row, rows) => rows.find(a => a.id === row.parentid)}
onSelectionChange={data=>{console.log(data)}}
options={{
actionsColumnIndex:-1,
toolbar:true,
paging:true,
selection:true
}}
localization={{...localization}}
/>
并在 componentDidMount 中得到我的回应
redFetch(`rolepermission?roleid=${id}`)
.then(res=>{
this.setState({rolepermission:res})
console.log(res)
let renderData=this.tableRolesRef.current.state.renderData
//renderData[0].tableData.checked=true
//this.tableRolesRef.current.setState({renderData}) ←that is what i want to set
console.log(this.tableRolesRef)
})