お世話になってます。
掲題の件で、今テキストボックスが複数あり
数個なら自分のコードで良いかなと思いますが、
数十となるとしんどいため、それを簡潔にできないか
悩んでいます。
お分かりの方居られましたら、
ご教示頂けないでしょうか?
以上、宜しくお願いします。
class App extends Component { constructor(props){ super(props); this.InsTodo = this.InsTodo.bind(this); this.UpdTodo = this.UpdTodo.bind(this); this.DelTodo = this.DelTodo.bind(this); this.state = {text:"d", text2:"dd", text3:"ddd",}; this.data = [ { value: '9to12', label: '9:00-12:00' }, { value: '12to14', label: '12:00-14:00' }, { value: '14to16', label: '14:00-16:00' }, { value: '16to18', label: '16:00-18:00' }, { value: '18to20', label: '18:00-20:00' }, { value: '20to21', label: '20:00-21:00' }, ]; } InsTodo(){ window.alert('Insert');} UpdTodo(){ window.alert('Update');} DelTodo(){ window.alert('Delete');} onChangeSelectValue(e) { this.setState({selectValue: e.target.value}); } render() { return ( <div className="App"> <form> <select defaultValue="14to16"> { this.data.map( d => <option value={d.value}>{d.label}</option>)} </select> <p> <input type="button" value="Ins" onClick={this.InsTodo}/> <input type="button" value="Upd" onClick={this.UpdTodo}/> <input type="button" value="Del" onClick={this.DelTodo}/> </p> //ここの箇所をスリムにしたい CST_CD: <input type="text" value={this.state.text} onChange={(e)=>this.setState({text: e.target.value})}/><br /> CST_NAME:<input type="text" value={this.state.text2} onChange={(e)=>this.setState({text2: e.target.value})}/><br /> TOWN_CD: <input type="text" value={this.state.text3} onChange={(e)=>this.setState({text3: e.target.value})}/><br /> </form> </div> ) } } export default App;
回答1件
あなたの回答
tips
プレビュー