我是React新手。目前,我正在使用反应引导表在我的应用程序中填充数据。我的任务是当用户点击表格的行时,它应该获取行的参数并重定向到不同的路由。
我的反应引导表代码如下
<BootstrapTable data={ this.state.userDetails } options={options}>
<TableHeaderColumn dataField='email' isKey>Email</TableHeaderColumn>
<TableHeaderColumn dataField='familyName'>Family Name</TableHeaderColumn>
<TableHeaderColumn dataField='givenName'>Given Name</TableHeaderColumn>
</BootstrapTable>
我传递给反应引导表的选项代码如下
const options={
onRowClick:function(row, rowIndex, columnIndex, event){
console.log(row);
console.log(event);
<Redirect to="/users/1" />;
}
}
有人可以让我知道我做错了什么吗?
编辑
我的完整代码如下
class ListView extends React.Component {
constructor(props) {
super(props)
this.state = {userDetails:[]}
}
onSubmit(values){
/*API Call done over here as the state needed to manipulated*/
const headers={
"Content-Type":"application/json",
"Authorization":cookies.get('idToken'),
"Access-Control-Allow-Origin":"*"
}
fetch(`${awsConfig.adminDevUrl}/users?email=${values.email}`,
{
method:"GET",
headers:headers
})
.then(response => response.json())
.then(data => {
if(data.length>0){
this.setState({userDetails:data});
}else{
this.setState({userDetails:[]});
}
this.props.reset();// Reset the form
})
.catch((error) => {
this.setState({userDetails:[]});
})
}
renderField(field){
const className=`form-group`;
const Field=`${field.label=='Password'? 'password':'text'}`
return (
<div className={className}>
<div className="input-group">
<span className="input-group-addon"><i className="fa fa-search" aria-hidden="true"></i></span>
<input className="form-control" type={Field} {...field.input}/>
</div>
</div>);
}
render() {
const { handleSubmit,history }=this.props;
const options={
onRowClick:function(row, rowIndex, columnIndex, event){
console.log(row);
console.log(event);
<Redirect to="/users/1" />;
}
}
return (
<div>
<div>
<NavigationBar />
<div className="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
<p><b> Search Users on the Platform </b></p>
<form onSubmit={handleSubmit(this.onSubmit.bind(this))}>
<Field name="email" component={this.renderField} label="Search" />
</form>
</div>
</div>
<div className="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
<BootstrapTable data={ this.state.userDetails } options={options}>
<TableHeaderColumn dataField='email' isKey>Email</TableHeaderColumn>
<TableHeaderColumn dataField='familyName'>Family Name</TableHeaderColumn>
<TableHeaderColumn dataField='givenName'>Given Name</TableHeaderColumn>
</BootstrapTable>
</div>
</div>
);
}
};