我开始练习ReactJS-(Laravel / Bootstrap)。我在将按钮(编辑和删除)添加到TableHeaderColumn的列时遇到问题。
问题: 该按钮未显示在列
上目标: 要查看用户的邮件到具有ID的其他页面。
状态:
constructor() {
super();
this.state = {
unread_mail_api:[]
}
this.viewmail = this.viewmail.bind(this);
}
设置状态:
axios.get('/api/dashboard').then(response => {
if(this.mounted)
{
this.setState({
unread_mail_api:response.data[0].mail_unread
})
}
}).catch(error => console.log(error));
可引导:
<BootstrapTable data={this.state.unread_mail_api} search pagination striped hover version='4'>
<TableHeaderColumn isKey dataField='id'>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='fullname'>Full Name</TableHeaderColumn>
<TableHeaderColumn dataField='subject'>Subject</TableHeaderColumn>
<TableHeaderColumn dataField='id' dataFormat={viewmail}>Action</TableHeaderColumn>
</BootstrapTable>
此功能必须在组件之外:
function viewmail(cell, row){
return <Link to={"/view/mail/"+cell} className='btn btn-outline-primary btn lg'>Edit</Link> ;
}