我是新的反應,我有一些困難檢索表中的行的輸入框的值。獲取所有值錶行輸入框
在我的渲染方法,我有一個表格,表格並保存所有按鈕,
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>
);
}
我的渲染方法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}中是錯誤的我甚至在打印this.phone_ $ index時看到該值handleSubmit方法:(但this.phone_0給了我一個錯誤 – Newbie
謝謝Shakula!但是當我嘗試獲取像這樣的值['fwd _ $ {index}'] .value時,我得到「無法讀取屬性值」undefined「。我怎樣才能從輸入和存儲中獲取所有值它的狀態onclick saveAll?我不知道如何檢索的值:(我不想保存價值onBlur) – Newbie