reactjs - index.js:1 Warning: Each child in a list should have a unique "key" prop
问题描述
I am studying reactjs and want to use Ant Design together, but now sure how to set rowKey in antd table. I have set it by using primary key from data source, but not sure why still got this error:
index.js:1 Warning: Each child in a list should have a unique "key" prop.
Any help is appreciated.
class DoctorList extends Component {
constructor(props){
super(props);
this.state = {
pageNumber: 1,
pageSize: 10,
keyWork:"",
// modal: cancel notification
visible:false,
doctorID:"",
// table header
columns:[
{title:"DoctorID", dataIndex:"doctorID", key:"doctorIdMenu", width:100},
{title:"First Name", dataIndex:"firstName", key:"firstName"},
{title:"Last Name", dataIndex:"lastName", key:"lastName"},
{title:"Medical Center", dataIndex:"medicalCenter", key:"medicalCenter"},
{title:"Management", dataIndex:"management", key:"management", width:200,
render:(text, rowData) =>{
return(
<div>
<Button className="delDoctorButton" onClick={()=>this.delDoctor(rowData.doctorID)} >Delete</Button>
<Button className="planButton" type="primary">
<Link to={{pathname: "/index/plan", state:{doctorid: rowData.doctorID}}} >Plan</Link>
</Button>
</div>
)
}
}
],
// tabel data
data:[{},],
};
}
// load data
componentDidMount() {
this.loadData();
}
// get doctor list
loadData = () => {
axios.get(`http://localhost:80/doctor-admin/src/api/api?action=readDoctorName`,{withCredentials:true})
.then(res => {
console.log(res.data);
const doctors = res.data;
if(doctors){
this.setState({
data:doctors
});
}
})
.catch((error) => {
console.log(error)
});
}
render(){
const { columns, data } = this.state;
return(
<Fragment>
<a className="addDoctor" style={{display: "table-cell"}} href = "/index/add">
<Button className="addDoctorButton" type="primary" htmlType="submit">
Add New Doctor
</Button>
</a>
<Table rowKey={record=> record.doctorID} columns={columns} dataSource={data} bordered />
</Fragment>
)
}
}
export default DoctorList;
解决方案
推荐阅读
- angular - 如何显示计数?
- php - 从表显示到文本框的 SQL 数据
- installation - Inno Setup - 在安装页面上隐藏进度条
- spring-boot - Paypal webhook 验证每次都失败
- angular - Angular:行为主体的值对象不可扩展
- nginx - 如何使用 uwsgi-socket 与 nginx 进行负载平衡
- node.js - Angular - TypeError 无法将 _id 设置为空值
- android - Android Studio AlarmManager 在特定时间没有运行
- sql - COUNT(*) 函数返回多个值
- java - 如何使用@RequestParam 捕获多个 url 参数?