React 处理form表单input输入项双向数据绑定
2016-04-12 18:51
639 查看
<form method="post" autoComplete="off" encType="multipart/form-data" onSubmit={this.onSubmit.bind(this)}> <div className={ 'title bl-line' + (state.activeInput == 'subject' ? ' active' : '') }> <input type="text" placeholder="标题" value={ state.form.subject } onChange={ this.setStateByKey.bind(this, 'subject') } onFocus={ this.setActiveInput.bind(this, 'subject') } onBlur={ this.setActiveInput.bind(this, '') } /> </div> <div className={ 'subject bl-line' + (state.activeInput == 'message' ? ' active' : '') }> <textarea placeholder="内容" value={ state.form.message } onChange={ this.setStateByKey.bind(this, 'message') } onFocus={ this.setActiveInput.bind(this, 'message') } onBlur={ this.setActiveInput.bind(this, '') } /> </div> <div className={ 'module bl-line' + (state.activeInput == 'fid' ? ' active' : '') }> <select value={ state.form.fid } onChange={ this.setStateByKey.bind(this, 'fid') } onFocus={ this.setActiveInput.bind(this, 'fid') } onBlur={ this.setActiveInput.bind(this, '') }> <option value="0">选择版块</option> { Object.keys(modules).map((key) => ( modules[key].map((item) => ( <option key={item.fid} value={item.fid}>{item.name}</option> )) )) } </select> </div> </form> // 双向数据绑定核心 setStateByKey(k, e) { let newForm = this.state.form; newForm[k] = e.target.value; this.setState({ form: newForm }); }
有疑问或技术交流,扫描公众号一起讨论学习。
更多React在线学习访问:http://each.sinaapp.com/react/index.html
阅读更多
相关文章推荐
- Bootstrap + AngularJS 双向数据绑定Form表单测试
- vue教程1-01 v-model 一般表单元素(input) 双向数据绑定
- angular4.0中form表单双向数据绑定正确姿势
- AngularJs中的双向向数据绑定(MVVM)与表单处理相关指令
- S2.3_Struts2_ActionGetInputFormData Action动作类接收用户输入表单数据的3种实现方式
- vue.js基础-处理用户输入与双向数据绑定
- React Native 处理TextInput在输入后,点击布局空白处软件盘能弹出和收回。
- jquery序列化form表单使用ajax提交后处理返回的json数据
- Form表单中的一种输入对象Input的不同类型
- ExtJs4 中 获取grid列表数据绑定到form表单
- spring mvc表单数据绑定,对于基本类型和日期的处理WebDataBinder
- 微信小程序简单实现form表单获取输入数据功能示例
- xml to html 双向数据绑定handlebars 处理
- PHP中使用php://input处理相同name值的表单数据
- PHP中使用php://input处理相同name值的表单数据
- mongodb - 前端form表单数据传输,在保存和清除的数据格式的处理程序的 - 非递归
- mongodb - 前端form表单传递数据,在保存和取出的数据格式处理函数 - 非递归
- js同时提交多个Form表单数据至后台的拼装处理
- 一步步学习微软InfoPath2010和SP2010--第三章节--表单设计基础:处理InfoPath布局、控件和视图(5)--理解数据绑定的基础
- React根据后台数据动态生成Form表单