react实现动态选择框.docx
第
react实现动态选择框
searchData.map((item,index)={
????????????returnColspan={8}flex,marginTop:5}}
??????????????Selectsort]}onChange={(value)={
????????????????//判断用户选择的选择项是否已经存在
????????????????if(exitChoseList.indexOf(value)==-1){
??????????????????//用户选择的选择项不存在的时候,判断是否已经有选择项了
??????????????????if(searchData[index][sort]!=){
????????????????????//要是存在选择项的话
????????????????????letobj=[...exitChoseList]
????????????????????//先把之前的选择项删除掉
????????????????????obj.splice(index,1)
????????????????????//添加新的选择项
????????????????????obj.push(value)
????????????????????setExitChostList(obj)
????????????????????letsearchDataObj=[...searchData]
????????????????????setSearchData([])
????????????????????//然后将其他的值都配置初始化
????????????????????searchDataObj[index][value]=[]
????????????????????searchDataObj[index][sort]=value
????????????????????searchDataObj[index][value_chose_list]=[1,2,3]
????????????????????setSearchData(searchDataObj)
??????????????????}else{
????????????????????//不存在选择项的话
????????????????????letobj=[...exitChoseList]
????????????????????setExitChostList([])
????????????????????//添加选择项
????????????????????obj.push(value)
????????????????????setExitChostList(obj)
????????????????????letsearchDataObj=[...searchData]
????????????????????setSearchData([])
????????????????????searchDataObj[index][sort]=value
????????????????????searchDataObj[i