表格中的React-select数组

时间:2018-04-16 07:43:12

标签: javascript reactjs redux react-select formik

我有一系列具有反应选择的字段。所以,如果我在一个索引中选择一个选项,那么在下一个索引中选择,该选项不应该是可见的。我该如何实现这一功能?我在OnBlur上调用以下函数。如果我删除所选的选项,它也会影响当前的选择。那么如何隐藏下一组字段中的选项

setTheatreList(values,setFieldTouched,index,options){
    setFieldTouched(`movie_screens_attributes[${index}].screen_id`,true)
    var i = options.findIndex(option => option.value == values.movie_screens_attributes[index].screen_id)
    debugger               
} 

1 个答案:

答案 0 :(得分:0)

 setScreenList(values,setFieldTouched,index,options){
    setFieldTouched(`movie_screens_attributes[${index}].screen_id`,true)
    if(index >= (this.state.previous_screens.length)){
        values.movie_screens_attributes.map(screen =>{
            if(this.state.previous_screens.includes(screen.screen_id)){

            }else{
                this.state.previous_screens.push(screen.screen_id)                    
            }
        })
    }
    else{
        const option = options.find(e => e.value == this.state.previous_screens[index])
        if(option){
            option.disabled = false
        }
        this.state.previous_screens[index]=values.movie_screens_attributes[index].screen_id    
    }

    if(options){
        var i = options.findIndex(option => option.value == values.movie_screens_attributes[index].screen_id)

        if(options[i]){

            options[i].disabled=true    
        }

        var flag = 0;
        for(i=0;i<options.length;i++){

            if(options[i].hasOwnProperty("disabled") && options[i]["disabled"]==true){

            }
            else{
                flag=-1
            }
        }
        if (flag ==0){
            var theatre_index =this.state.theatres.findIndex(option => option.value == values.movie_screens_attributes[index].theatre_id)
            if(this.state.theatres[theatre_index]){
                this.state.theatres[theatre_index].disabled=true
                debugger
            }
        }
    }
}