背景
我将根据选择框中的值过滤表格。我在理解state
和props
内有困难react.js
。一旦我传递了值,我就可以轻松地进行过滤,但我正在尝试以“react”的方式来做到这一点。
问题
如何将SelectionBox
选择或更改TableDisplay
时的值传递给用户选择其中一个选项时的值?
例子
class SelectionBox extends React.Component {
render() {
return <div className="filter">
<label for="business">Filter by Status
<select id="business" name="business">
<option value="all">All Requests</option>
<option value="approved">Approved</option>
<option value="pending">Pending</option>
<option value="denied">Denied</option>
</select>
</label>
</div>;
}
}
class TableDisplay extends React.Component {
render() {
return <div className="wrapper">
<h1>Requests</h1>
<SelectionBox />
<div><table className="table">
<tr className="seperate"><td>Title</td><td>Status</td><td>Created</td><td>Updated</td><td>Delete</td></tr>
{Object.keys(requests).map(function(key) {
let styling = "bg-plain";
if (requests[key].status == "Approved") {
styling = "bg-success";
} else if (requests[key].status == "Denied") {
styling = "bg-danger";
}
return <tr className={styling}>
<td>{requests[key].title}</td>
<td>{requests[key].status}</td>
<td>{requests[key].created_at.slice(0, 10)}</td>
<td>{requests[key].updated_at.slice(0, 10)}</td>
<td><a href="">Delete</a></td>
</tr>;
})}
</table>
</div></div>;
}
}
研究
从阅读中我认为我需要在这里实现的是,里面 SelectionBox
constructor(props) {
super(props);
this.state = {
// Something referring to the state of the select box here
};
};
然后props
从内部访问TableDisplay
?