由于某些原因,当我尝试将JavaScript输入到HTML部分的角度部分时,它不起作用。我使用的是Thymeleaf和react版本15.0.0
下面是HTML部分:
<button className="btn btn-info" onClick={this.displayInfo}>Click for info about {firstName[i]}</button>因此,在这种情况下,它不工作并返回一个错误:
unexpected error (type=Internal Server Error, status=500) Exception parsing document如果我移除onClick={this.displayInfo},它将会工作。
我的函数:
displayInfo(){
console.log("it worked");
}
The render() function:
render(){
var {number, firstName, lastName} = this.state;
var rows = [];
for (var i in number)
{
rows[i] = (<tr>
<td>{number[i]}</td>
<td>{firstName[i]}</td>
<td>{lastName[i]}</td>
<td><button className="btn btn-info" onClick={this.displayInfo}>Click for info about {firstName[i]}</button></td>
</tr>);
}
var headers = <tr><th>Number</th><th>First Name</th><th>Last Name</th><th>Extra Info</th></tr>;
return (<table className="table table-bordered">
<thead>{headers}</thead>
<tbody>{rows}</tbody>
</table>);
}发布于 2017-09-07 19:33:31
onClick处理程序似乎是错误的。
const YourComponent extends Component {
constructor() {
this.displayInfo = this.displayInfo.bind(this)
}
displayInfo() {
console.log('do your thing')
}
render() {
return (
<button
className="btn btn-info"
onClick={this.displayInfo}
>
Click for info about
</button>
)
}
}https://stackoverflow.com/questions/46095259
复制相似问题