【发布时间】:2020-11-09 00:53:21
【问题描述】:
我是 Reactjs 的初学者,我从对象数组创建数组并创建表现在我想对创建的表执行搜索操作。我尝试了很多,但我无法得到我应该在 updateSearch() 函数中编写的内容来从表中搜索并显示搜索结果,以及 通过单击列名通过升序和降序对数据进行排序。所以,请帮我解决这个问题
class Hello extends Component {
constructor(props) {
super(props)
this.state = {
search: '',
Data:[
{
id: 1,
fullName: 'abc',
email:'example@gmail.com',
},
{
id: 2,
fullName: 'qps',
email:'qps@gmail.com',
},
{
id: 3,
fullName: 'qwe',
email:'qwe@gmail.com',
},
]
}
}
updateSearch(event){
this.setState({
search : event.target.value
});
console.log(event.target.value);
}
render() {
return (
<div>
<h1>welcome to React</h1>
<input type="text" placeholder="Enter item to be searched" value={this.state.search} onChange={this.updateSearch.bind(this)} />
<table className="table table-hover table-dark">
<tbody>
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Email</th>
</tr>
{
this.state.Data.map((item,index)=>(
<tr key={item.id}>
<td >{item.id}</td>
<td >{item.fullName}</td>
<td>{item.email}</td>
</tr>
))
}
</tbody>
</table>
</div>
)
}
}
export default Hello
【问题讨论】:
-
您要搜索哪个属性?
id、fullName或email? -
您一次只需要问一个问题。
标签: reactjs