【发布时间】:2019-07-04 21:25:42
【问题描述】:
我创建了一个已经由一些数据填充的表。现在我想根据下拉值中的选择过滤表中的结果。我怎么能在 React 中做到这一点?有人可以指导或提供示例代码来展示结果吗?
下面是我的代码示例:
下拉菜单:
<table>
<tbody>
<tr> <td>
<label className="col-form-label"> Auditee </label> </td>
<td className="td-padding td-space">
<select className="form-control dpwidth" onChange={this.optionSelected.bind(this)}>
<option>Select</option>
{this.renderAuditee()}
</select>
</td>
<td> <label className="col-form-label lbl-space"> SME </label></td>
<td className="td-padding">
<select className="form-control dpwidth" onChange={this.optionSelected.bind(this)}>
<option>Select</option>
{this.renderSME()}
</select>
</td>
<td> <label className="col-form-label lbl-space"> Year </label></td>
<td className="td-padding">
<select className="form-control dpwidth" name="Year" onChange={this.handlePeriodChange.bind(this,this)} disabled={this.state.isChecked}>
<option>Select</option>
{this.renderYear()}
</select>
</td>
</tr>
</tbody>
</table>
表格中的数据:
<table className="table table-striped table-highlight">
<span className="head">Review2</span>
<tbody>
<tr>
<th> Project ID </th>
<th> Project Name </th>
<th> SME </th>
<th> Auditor </th>
<th> EEECPM</th>
<th> WorldArea </th>
<th> Country </th>
<th> FY Year </th>
<th> FY Period </th>
<th> Review1 Date </th>
<th> No. of Obs. </th>
<th> Total Recom. </th>
<th> Accepted Recom.</th>
</tr>
{
filteredData.length? this.renderTableData(filteredData) : this.renderTableData(data)
}
</tbody>
</table>
【问题讨论】:
标签: javascript reactjs