【发布时间】:2016-09-17 12:29:49
【问题描述】:
我正在使用以下代码生成一个简单的 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>×</button>
</form>
</div>
)
}
我试着做这样的事情;
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>×</button>
</form>
</tr>
</tbody>
</table>
)
}
但它并没有像我预期的那样工作。我使用react-express-examplar 作为我的起点。
如何让 Bootstrap 表在我的 React 应用程序中工作?
【问题讨论】:
-
<table class="table table-striped">你不应该使用className而不是class吗? -
@JacobGoh - 谢谢我已经尝试过但没有成功,您能否将您提供的解决方案与正确的上下文添加为答案?
-
我知道 reactjs 但不知道 bower。无法进一步帮助您。顺便说一句,我注意到你错过了代码中的结束表标记
-
另一个建议,我喜欢首先编写 html 代码,确保它可以工作,然后才使用 magic.reactjs.net/htmltojsx.htm 将 html 转换为 jsx。这有助于我完全避免 jsx 语法错误
-
我看到很多事情都做错了,不知道你是写错了还是实际上是一个错误。你能提供一个jsfiddle吗?
标签: reactjs react-jsx react-bootstrap react-bootstrap-table