私は反応が新しく、テーブルの行の入力ボックスの値を取得するのにいくつかの困難があります。私は、フォーム、テーブルを持っているし、すべてのボタンを救う私のrenderメソッドですべての値を取得するテーブル行の入力ボックス
、
render() {
return (
<div>
<form onSubmit={this.handleSubmit}>
{ (this.state.inputList.length > 0) ?
(<div>
<table id='configtable'>
<tbody>
{this.state.inputList}
</tbody>
</table>
<table id="table-footer">
<tfoot>
<tr>
<td />
<td>
<input name="fwdAllNumber" type="number" placeholder="Phone Number" pattern="[0-9]*" inputMode="numeric" onChange={this.handleFwdAllInput}/>
</td>
<td>
<ButtonGroup className="button-group-right">
<Button className="config-button" type="submit" value="Submit" onClick={this.saveAll}>Save All</Button>
</ButtonGroup>
</td>
</tr>
</table>
</div>
) : (<div><br/><h4>No Phone Numbers currrently exist. Please click "Add Phone Number" to begin</h4></div>)}
</form>
</div>
)
}
})
AddRowメソッドは、 "行を追加" ボタン
addRow(event) {
const inputList = this.state.inputList;
const index = this.state.index;
let rows = this.state.rows;
const row = (
<tr key={ inputList.length } name={ inputList.length }>
<td key={index}><input name={'phone_'+index} type="number" placeholder="Foward Phone Number" pattern="[0-9]*" inputMode="numeric" ref={(input) => this.phone_$index = input} type="text"/> </td>
<td><input name={'fwd_'+index} type="number" placeholder="Foward Phone Number" pattern="[0-9]*" inputMode="numeric" ref={(input) => this.fwd_$index = input} /></td>
<td id="forwarded-indicator">
<div id="forwarded-indicator-div" />
</td>
</tr>
);
}
IのレンダリングメソッドたonPressに行を追加saveAllボタンを押すと、すべての行の入力ボックスの値をすべて取得する必要があります。
私が試した、
handleSubmit: function(event) {
event.preventDefault();
let rows = this.state.rows;
const tableValues = this.state.inputValueList;
let configVal = [];
for(let i = 0; i < rows.length; i++){
console.log(this.phone_ + i.value);
}
},
しかし、私はここにナンを取得し、コンソールに私が得る、
<input type="text" name="phone_0" placeholder="Foward Phone Number" pattern="[0-9]*" inputmode="numeric">
<!-- react-text: 162 -->
<!-- /react-text -->
誰も私が をONSUBMIT助けることができれば、私は本当に感謝されるだろう
ありがとう
'handleFwdAllInput'関数を表示すると、入力変数を状態変数に格納していますか? –
はい、私のconcatが間違っていると思うref = {(input)=> this.phone_ $ index = input}私はhandleSubmitメソッドでthis.phone_ $インデックスを印刷しても値を参照してください:(しかしthis.phone_0は私にエラー – Newbie
Thanks Shakula!しかし、この['fwd _ $ {index}'] .valueのような値を取得しようとすると、 "未定義のプロパティ 'value'を読み込めません。それはsaveAllのonclickを述べる?私は値を取得する方法がわからない:(私はonBlurの値を格納したくない) – Newbie