【发布时间】:2016-03-20 02:25:14
【问题描述】:
我正在构建一个表格,该表格有一个普通行,然后是隐藏的两行,直到单击加号图标。单击该图标时,它应变为减号,隐藏行应更改 CSS 类。也应该反过来工作。
import React from 'react';
class HiddenRow extends React.Component {
render() {
return (
<tr className="hidden-row">
<td>Stuff</td>
</tr>
);
}
}
class NormalRow extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
console.log('here');
// Expand rows if hidden change icon to fa-minus-circle
// Hide rows if not and change icon to fa-plus-circle
}
render() {
return (
<tr>
<td><i className="fa fa-plus-circle" onClick={this.handleClick}></i> Hello</td>
</tr>
);
}
}
class ParentDiv extends React.Component {
render() {
return (
<div>
<table>
<tbody>
<NormalRow />
<HiddenRow />
<HiddenRow />
<NormalRow />
<HiddenRow />
<HiddenRow />
</tbody>
</table>
</div>
);
}
}
编辑:该表将有多组普通行和隐藏行。单击正常行中的图标应仅切换两个直接隐藏的行。当我使用 Angular 但切换到 React 时,我正在使用 JQuery 来执行此操作。我一直在使用 JQuery 和 React 作为解决方案。
【问题讨论】:
标签: reactjs