问题描述
我正在尝试通过搜索创建简单列表,但是在使用状态时遇到问题。当我添加构造函数时,该程序无法正常工作。也许我需要以其他方式从Rails传输数据,但是如何?我该怎么办?
Label.js:
import React from "react"
import PropTypes from "prop-types"
class ProductRow extends React.Component {
render() {
return (
<tr>
<td>{this.props.product}</td>
<td>{this.props.body}</td>
<td>{this.props.price}</td>
</tr>
);
}
}
class ProductTable extends React.Component {
render() {
const rows = [];
rows.push(
<ProductRow
product={this.props.name}
price={this.props.price}
body={this.props.body}
key={this.props.id}
/>
);
return (
<table>
<thead>
<tr>
<th>Name</th>
<th>Body</th>
<th>Price</th>
</tr>
</thead>
<tbody>
{rows}</tbody>
</table>
);
}
}
class Label extends React.Component {
render () {
return (
<React.Fragment>
{<ProductTable name = {this.props.label} price = {this.props.price} id ={this.props.id} body = {this.props.body} /> }
</React.Fragment>
);
}
}
Label.propTypes = {
id: PropTypes.number,label: PropTypes.string,price: PropTypes.number,body: PropTypes.string,};
export default Label
有我的rails代码:
<%= react_component("Label",{ label: product.title,price: product.price,body: product.body,id:product.id,}) %>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)