[英]Passing params in ES6 (React), SyntaxError: unknown: Unexpected token
Trying to build a react component that generates a table. 尝试构建一个可生成表的react组件。 It calls a rails api to get its data.
它调用rails api来获取其数据。 Data arrives at this component as an array of hashes.
数据作为哈希数组到达此组件。
On line 13 below I get 'SyntaxError: unknown: Unexpected token'. 在下面的第13行,我收到“ SyntaxError:未知:意外令牌”。
I want to move the logic for creating a row to a method (makeRow). 我想将创建行的逻辑移到方法(makeRow)。 I am missing something obvious.
我缺少明显的东西。 I can access the hashes just fine, display them in a table row, but I can't figure out how to pass the hash to the makeRow method.
我可以很好地访问散列,将它们显示在表格行中,但是我不知道如何将散列传递给makeRow方法。 As indicated by the comment in the code, it throws a syntax error on line 13.
如代码中的注释所示,它在第13行上引发语法错误。
class ProductsTable extends React.Component {
constructor(props) {
super(props);
}
render(){
if (this.props.data){
let rows = [];
//debugger
for ( var i =0; i < this.props.data.length; i++){
//debugger
//this.props.data[i] = {id: 5, name: "Enfield", description: "Bullet 500", price: "$5000005"}
rows.push(<tr>{< this.makeRow(this.props.data[i]) />}</tr>)
// ^ SyntaxError: unknown: Unexpected token
}
return (
<div>
<table id="product-table">
<tbody>
{ rows }
</tbody>
</table>
</div>
)} else {return(null)};
}
makeRow(row){
//debugger
return (<td> row.name </td>);
}
}
Angle bracket is reserved for component only. 尖括号仅保留给组件使用。 If we have any component, we should use
<MyComponent />
. 如果有任何组件,则应使用
<MyComponent />
。 For JavaScript inside jsx, we have to use plain JavaScript logic by enclosing curly bracket only. 对于jsx中的JavaScript,我们必须仅通过使用大括号来使用纯JavaScript逻辑。
<MyComponent>{this.state.name}</MyComonent>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.