超全模态模型 × Harness 升级,升级解锁 ArkClaw,最新支持 DeepSeek-V4 系列与 GLM-5.1
不管是静态的预设选项,还是后续要从接口拉取的动态数据,我们都可以先把它存在组件的state中。比如针对你代码里的experience字段,咱们可以给它初始化一组选项:
experience
import React from 'react'; import ReactDOM from 'react-dom'; import axios from 'axios'; class SearchForm extends React.Component { constructor(props) { super(props) this.state = { position: '', area: '', date: '', experience: '', // 改成单个值,用来绑定select的选中状态 experienceOptions: ['应届生', '1-3年', '3-5年', '5年以上'] // 新增选项数组 } this.handlePositionChange = this.handlePositionChange.bind(this); this.handlePositionKeyUp = this.handlePositionKeyUp.bind(this); this.handleAreaChange = this.handleAreaChange.bind(this); this.handleExperienceChange = this.handleExperienceChange.bind(this); // 新增处理函数绑定 } // 新增experience的change处理函数 handleExperienceChange(e) { this.setState({ experience: e.target.value }); } // 你的其他方法...
接下来在组件的render方法中,找到对应的标签,通过map方法遍历state里的选项数组,自动生成每个标签: render() { return ( <form> {/* 其他表单元素... */} <select value={this.state.experience} onChange={this.handleExperienceChange} > {/* 遍历选项数组生成option */} {this.state.experienceOptions.map((option, index) => ( <option key={index} value={option}> {option} </option> ))} </select> {/* 其他表单元素... */} </form> ) } 3. 如果是动态接口获取选项的情况 # 要是你的选项数据需要从后端接口获取,那可以在componentDidMount生命周期钩子中发起请求,拿到数据后更新state,这样组件首次渲染时就能拿到生成好的option了: componentDidMount() { // 用axios请求选项数据 axios.get('/api/experience-options') .then(res => { this.setState({ experienceOptions: res.data }); }) .catch(err => { console.error('获取选项数据失败:', err); }); } 一些小提醒: # 每个都要加唯一的key属性,这里用index是简单方案,如果选项有唯一ID的话用ID会更稳妥; 确保的value和state里的对应字段绑定,这样能实现受控组件的效果;
value
experience: '1-3年'
内容的提问来源于stack exchange,提问作者user9521163
超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起
模型再升级,30秒超长叙事, 模态参考扩容
模型自由,工具不限,最新支持 Deepseek-V4 系列、GLM-5.3 系列
超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列
大模型19元起,Al应用9.9元畅享,新人首购爆款尽享优惠