0

我有一个具有反应选择的字段数组。所以如果我在一个索引中选择一个选项,然后在下一个索引中选择,该选项应该不可见。我怎样才能实现这个功能?我正在调用以下函数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               
} 
4

1 回答 1

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
            }
        }
    }
}
于 2018-04-27T08:26:23.703 回答