私はリアクションを学んでおり、簡単なToDoリストを構築しています。私は今、私は、チェックボックスをクリックして、1Reactjsは、チェックされた入力に基づいてオブジェクトのプロパティの状態を変更します。
にプロパティdone
の状態を変更したいマイtodolistのコンポーネントは、このマップ機能を持っている私の
initialState
getInitialState:function(){
return {
items: [
{
text:"Buy Fish",
key: "1",
done: 0
}
]
}
},
に
var listItem = this.props.items.map((item, index)=>{
return <li key={item.key}> <input type="checkbox" onChange={(e)=>{this.props.onChange(item.key, e)}} /> <span onClick={()=>{this.props.editItem(item.text)}}>{item.text}</span> <button onClick={()=>this.props.removeItem(item.key)}>x</button> </li>
});
をこのオブジェクトを持っています
onChange小道具は関数につながっています
itemDone:function(index, e){
var myArray = this.state.items;
var a = e.target.checked;
console.log(index);
},
値を0から1に変更する正しい方法は何ですか?