formik 中的 React-select 数组
Array of React-select in formik
我有一个已反应的字段数组 select。所以如果我 select 一个索引中的选项,那么在下一个索引中,select,该选项不应该是可见的。我怎样才能实现这个功能?我在 OnBlur
上调用以下函数。如果我删除 selected 选项,它会影响当前 selection too.So 如何在下一组字段中隐藏该选项
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
}
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
}
}
}
}
我有一个已反应的字段数组 select。所以如果我 select 一个索引中的选项,那么在下一个索引中,select,该选项不应该是可见的。我怎样才能实现这个功能?我在 OnBlur
上调用以下函数。如果我删除 selected 选项,它会影响当前 selection too.So 如何在下一组字段中隐藏该选项
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
}
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
}
}
}
}