我试图创建一个基于react_on_rails
宝石一个示例应用程序无法正常工作。在我反应过来的代码反应inbuild功能像onChange
或onSubmit
不工作。阵营的onChange方法react_on_rails
我HelloWorldWidget
组件看起来是这样的。
...
constructor(props, context) {
super(props, context);
_.bindAll(this, 'handleChange');
}
handleChange(e) {
const name = e.target.value;
console.log(name);
//this.props.updateName(name);
}
render() {
const { name } = this.props;
return (
<div className="container">
<h3>
Hello, {name}!
</h3>
<input className="form-control input-sm col-sm-4" type="text" onChange={this.handleChange}/>
</div>
);
}
另外,如果我禁用服务器端在我views/hello_world/index.html.erb
文件我的组件的预渲染,则该组件没有渲染的UI。
<%= react_component("HelloWorldApp", props: @hello_world_props , prerender: false) %>
GitHub库:react-on-rails-sample-app
你得到错误?什么是'_.bindAll(this,'handleChange');'? –
没有错误。它是lodash函数,它将我们所有的函数绑定到'this'上下文中。 –