Twitter bootstrap 使用react引导展开表内的行

Twitter bootstrap 使用react引导展开表内的行,twitter-bootstrap,reactjs,html-table,react-bootstrap,Twitter Bootstrap,Reactjs,Html Table,React Bootstrap,我正试图通过以下方式实现以下目标: 我现在的react代码如下,但不起作用: <Table> <thead> <tr> <th>Job Name</th> <th>Description</th> <th>Provider Name</th> <th>Region</th> &l

我正试图通过以下方式实现以下目标:

我现在的react代码如下,但不起作用:

<Table>
<thead>
    <tr>
        <th>Job Name</th>
        <th>Description</th>
        <th>Provider Name</th>
        <th>Region</th>
        <th>Status</th>
    </tr>
</thead>
<tbody>
    <tr data-toggle="collapse" data-target="#demo1" className="accordion-toggle">
        <td>OBS Name</td>
        <td>OBS Description</td>
        <td>hpcloud</td>
        <td>nova</td>
        <td> created</td>
    </tr>
    <tr>
        <td colspan="12" className="hiddenRow">
            <div className="accordian-body collapse" id="demo1">
                <h1>Hi from the hiddenRow</h1>
            </div>
        </td>
    </tr>
</tbody></Table>

职务名称
描述
提供者名称
区域
地位
OBS名称
OBS描述
hpcloud
新星
创建
hiddenRow来的你好

表格显示正确,但单击时行不会展开。

您的代码对我有效-单击时切换隐藏行。检查此引导程序:


也许您没有加载JQuery

现在它变得容易多了,因为Bootstrap实现了折叠功能。看


#
日期
描述
信用
借记
平衡
1.
2013年5月5日
信用账户
$150.00
$150.00
演示内容1
私有onClickHandler(e:React.MouseEvent){
常量hiddenElement=e.currentTarget.nextSibling.firstChild.firstChild作为HTMLElement;
hiddenElement.className.indexOf(“折叠入”)>-1?hiddenElement.classList.remove(“入”):hiddenElement.classList.add(“入”);
}
我将的答案改编为react and的新版本:

onClickHandler=(e)=>{
常量hiddenElement=e.currentTarget.nextSibling;
hiddenElement.className.indexOf(“折叠显示”)>-1?hiddenElement.classList.remove(“显示”):hiddenElement.classList.add(“显示”);
};

#
日期
描述
信用
借记
平衡
1.
2013年5月5日
信用账户
$150.00
$150.00
演示内容1

很抱歉,我可能不够清楚,但我是在用ReactBootstrap的javascript东西做这件事,它依赖于JQuery。通常,最好解释一个解决方案,而不是仅仅发布几行匿名代码。您可以阅读,而且它只是行上的一个切换,将在“collapse”类附近添加/删除“in”类。
<table class="table table-condensed" style="border-collapse:collapse;">
    <thead>
        <tr>
            <th>#</th>
            <th>Date</th>
            <th>Description</th>
            <th>Credit</th>
            <th>Debit</th>
            <th>Balance</th>
        </tr>
    </thead>
    <tbody>
        <tr onClick={this.onClickHandler}>
            <td>1</td>
            <td>05 May 2013</td>
            <td>Credit Account</td>
            <td class="text-success">$150.00</td>
            <td class="text-error"></td>
            <td class="text-success">$150.00</td>
        </tr>
        <tr >
            <td colspan="6" class="hiddenRow"><div class="collapse" id="demo1"> Demo Content1 </div> </td>
        </tr>       
    </tbody>
</table>

private onClickHandler(e: React.MouseEvent<HTMLTableRowElement>) {
  const hiddenElement = e.currentTarget.nextSibling.firstChild.firstChild as HTMLElement;
  hiddenElement.className.indexOf("collapse in") > -1 ? hiddenElement.classList.remove("in") :  hiddenElement.classList.add("in");
}
<Table>
    <thead>
    <tr>
        <th>#</th>
        <th>Date</th>
        <th>Description</th>
        <th>Credit</th>
        <th>Debit</th>
        <th>Balance</th>
    </tr>
    </thead>
    <tbody>
    <tr onClick={this.onClickHandler}>
        <td>1</td>
        <td>05 May 2013</td>
        <td>Credit Account</td>
        <td className="text-success">$150.00</td>
        <td className="text-error" />
        <td className="text-success">$150.00</td>
    </tr>
    <tr className="collapse">
        <td colSpan="6">
            Demo Content1
        </td>
    </tr>
    </tbody>
</Table>