我是新的反应,我有一些困难检索表中的行的输入框的值。获取所有值表行输入框
在我的渲染方法,我有一个表格,表格并保存所有按钮,
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