Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/420.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在react native中为不同的值切换onChange_Javascript_React Native_Toggle - Fatal编程技术网

Javascript 在react native中为不同的值切换onChange

Javascript 在react native中为不同的值切换onChange,javascript,react-native,toggle,Javascript,React Native,Toggle,我有一个api的响应,它作为一个对象出现。我必须在不同值的切换中填充它们。这必须发生在onChange方法上。例如,如果该值为“是”,则必须将其设置为“否”。如果该值为“真”,则必须将其设置为“假” example of response from api = {lyrics: "True",versions:'on',statue:'false'} during the onChange method, I have to set them to the corresp

我有一个api的响应,它作为一个对象出现。我必须在不同值的切换中填充它们。这必须发生在onChange方法上。例如,如果该值为“是”,则必须将其设置为“否”。如果该值为“真”,则必须将其设置为“假”

example of response from api  = {lyrics: "True",versions:'on',statue:'false'}

during the onChange method, I have to set them to the corresponding true or false 
  state = {
        options:{}
        }
  
<View style={{flexDirection:'row',marginVertical:5}} key={index}>
      <Toggle
      size='small'
      initialValue={this.state.options[content.key]}
      onChange={()=>{
       let filteroptions = {...this.state.options}
       let value
       if(content.value == "no"){
         
       filteroptions[content.key] = 'yes'
       }
      else if(content.value == "yes"){
        filteroptions[content.key] = 'no'
       }
       if(content.value == "True"){
       filteroptions[content.key] = 'False'
       }
      else if(content.value == "False"){
       filteroptions[content.key] = 'True'
       }
       console.log("this.state.filterOptions",filteroptions[content.key],value)
       
         //console.log("options",filteroptions[content.key])
        //this.setState({options:filteroptions})
      }}
      
      selected={this.state.options[content.key] == content.value}
      />
      <VFText i18nKey={content.label} style={[styles.sectionContentText, 
       {marginLeft:7,marginTop:4}]} />
    </View>
来自api的响应示例={歌词:“True”,版本:'on',雕像:'false'}
在onChange方法中,我必须将它们设置为相应的true或false
状态={
选项:{}
}
{
让filteroptions={…this.state.options}
让值
如果(content.value==“否”){
filteroptions[content.key]=“是”
}
else if(content.value==“是”){
filteroptions[content.key]=“否”
}
如果(content.value==“True”){
filteroptions[content.key]=“False”
}
else if(content.value==“False”){
filteroptions[content.key]=“True”
}
log(“this.state.filterOptions”,filterOptions[content.key],value)
//log(“选项”,过滤器选项[content.key])
//this.setState({options:filteroptions})
}}
selected={this.state.options[content.key]==content.value}
/>

代码有什么问题?你会得到什么样的错误?你期望得到什么?