これは非常に簡単な例です。私は、フォームを持っていると私は私がref
を使用する必要が隠しフィールドの値を必要とする:React Refs 'の値が表示されない
<form>
<input ref="num" type="hidden" name="amount" value="99"/>
</form>
var number = this.refs.num.value;
console.log(number); // nothing
console.log(this.refs.num); // shows the field
参照して値を取得する方法は?
'this.refs.num.value'は正しいです。あなたのコードにもう少しコンテキストを提供できますか?あなたは 'this.refs'をどこで手に入れようとしていますか? –
@BradColthurst関数から。 'foo:function(){...}' – Sylar
関数をどこで呼びますか? –