複数の入力があります。どの入力が変更されたかをどのように知ることができますか?私はそれを行う一つの方法は、私は私のhandleChange関数に追加のパラメータを渡すことができると思う。私はjsxでこれを行うことができることを知っていますonChange={this.handleChange.bind(this, 'name');
しかし、コンストラクタが関数をバインドしていたので、それを行う方法がわかりません。反応でコンストラクタを使用している間に追加のparam関数を渡します。
class HelloWorldComponent extends React.Component {
constructor(){
super();
this.handleChange = this.handleChange.bind(this);
this.state = {
name:"",
age:""
}
}
render() {
const person = {"name":"james", "age":18};
return (
<div>
<input onChange={this.handleChange} type="text" placeholder="name" defaultValue={person.name} /><br />
<input onChange={this.handleChange} type="text" placeholder="age" defaultValue={person.age} />
</div>
);
}
handleChange(e){
// how to get name and age here?
console.log(e.target.value)
}
}
http://jsbin.com/cubofurihu/edit?js,console,output
JSのonClickは値を渡すことはできません。
handleChange
を想定しです方法](http://stackoverflow.com/questions/29810914/react-js-onclick-cant-pass-value-to-method) –