<input style={{flex:'2'}} type="text" ref={input => this.input = input} defaultValue="" placeholder='请输入关键词查询'/>
<select style={{flex:'1',marginRight:'10px'}} ref={select => this.select = select} >
<option value=''>全部</option>
{
this.state.cityData.length==0?'':this.state.cityData.map((item)=>
<option key={item.key} value={item.key}>{item.value}</option>
)
}
</select>
在需要获取标签元素value的时候:
const inpVal = this.input.value;
const selVal=this.select.value;
getCities=()=>{
axios.ajax({
url:'/api/v1/vas/areas',
method:'get',
data:{}
}).then((res)=>{
if(res.code===0){
let arr=[]
for(var i in res.data){
arr.push({key:i,value:res.data[i]});
}//将后台获取的数据格式转成select标签需要的{key:0,value:"xxx"}形式
this.setState({cityData:arr});
}
});
}
网友评论