初めての方はReact
です。子フォームコンポーネントReactJSから小道具を入手
複数の(状態に基づいて)入力ボックスを含むコンポーネントArrayInput
を作成しています。
ArrayInput
は、各入力ボックスのonChangeイベントを処理する必要があります。
私は多くの記事やドキュメントを検索しますが、正しい方法を見つけることができませんこれらの劇的生成された入力ボックス
上のいくつかの特定の小道具/属性(この場合は、「インデックス」)を取得することを願っています。
this.ref[inputBoxRef]
(反応14+)を使用して実際のDOMノードを取得できますが、$(domnode).attr('index')
または$(domnode).data('index')
を使用すると、属性またはデータがないことがわかります。
window.ArrayInput = React.createClass({
......other methods
handleChange:function(ref,event){
var domInputBox = this.refs[ref];
//trying to get the index attribute of this input
}
render:function(){
var self = this;
return (
<div className="input-wrapper" >
<label>
<div>{this.props.label}</div>
{
this.state.value.map(function(e,i){
return (
<input type="text"
ref={"arrayBox"+i}
key={"arrayBox"+i}
index={i} //custom attribute
value={e}
onChange={self.handleChange.bind(self,"arrayBox"+i)}
/>
)
})
}
</label>
</div>
)
}
});
あなたは '$(e.target)'を試しましたか? – t1m0n