如何让我的React应用程序使用crud渲染Bootstrap表

5 reactjs react-jsx react-bootstrap react-bootstrap-table

我正在使用以下代码生成一个简单的UI,我正在尝试将其转换为使用Bootstrap.

这是我的原始代码(使用Skeleton);

render:function(){
        return (
            <div className="grocery-item row">
                <div className="six columns">
                    <h4 className={this.props.item.purchased ? "strikethrough" : "" }>
                        {this.props.item.name}
                    </h4>
                </div>
                <form onSubmit={this.togglePurchased} className="three columns">
                    <button className={this.props.item.purchased ? "btn btn-danger" : "button-primary"}>{this.props.item.purchased ? "unbuy" : "buy"}</button>
                </form>
                <form className="three columns" onSubmit={this.delete}>
                    <button>&times;</button>
                </form>
            </div>
        )
    }
Run Code Online (Sandbox Code Playgroud)

我尝试过做这样的事情;

render:function(){
        return (        
          <table class="table table-striped">
            <thead>
              <tr>
                <th>Column 1</th>
                <th>Columan 2</th>
                <th>Columan 3</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <h4 className={this.props.item.purchased ? "strikethrough" : "" }>{this.props.item.name}</h4>
                <form onSubmit={this.togglePurchased} className="three columns">
                  <button className={this.props.item.purchased ? "btn btn-danger" : "button-primary"}>{this.props.item.purchased ? "unbuy" : "buy"}</button>
                </form>
                <form className="three columns" onSubmit={this.delete}>
                    <button>&times;</button>
                </form>
              </tr>
            </tbody>
          </table>
        )
    }
Run Code Online (Sandbox Code Playgroud)

但它并没有像我期望的那样发挥作用.我react-express-examplar用作我的出发点.

如何在我的React应用程序中使用Bootstrap表?

小智 -1

根据我的理解,您希望名称和购买/取消购买按钮作为一行出现在相应的列下。在tr标签中,将每个html部分作为td标签请参考下面的html片段:

 <td>
  <h4 class="strikethrough">
                    name
  </h4>
</td>
<td>
  <form class="three columns">
      <button class="btn btn-info">buy</button>
  </form>
</td>
<td>
  <form class="three columns">
      <button>&times;</button>
  </form>
</td>
Run Code Online (Sandbox Code Playgroud)

请尝试类似地修改组件渲染方法中的 html。