React native 如何在react native中使用复选框?

React native 如何在react native中使用复选框?,react-native,jsx,React Native,Jsx,我得到了一个用户可以选择的主题列表,之后我将根据他们选择的主题进行api调用,我让所有的工作,但我需要将文本更改为复选框 这是我的状态: this.state = { loading: false, dataSource: [], error: null, topic: '', } getUsers = () => { fetch('https://someapi.com/?topic=' + this.stat

我得到了一个用户可以选择的主题列表,之后我将根据他们选择的主题进行api调用,我让所有的工作,但我需要将文本更改为复选框

这是我的状态:

     this.state = {
      loading: false,
      dataSource: [],
      error: null,
      topic: '',
  }
   getUsers = () => {
    fetch('https://someapi.com/?topic=' + this.state.topic, {method: 'GET'}).then((response) => response.json()).then((responseJson) => {
      this.setState({
        loading: false,
        error: responseJson.error || null,
        dataSource: responseJson.data.users,
      });
    }).catch((error) => {
      this.setState({error, loading: false});
    });
  }
    <View>
     <Text onPress={(text) => this.setTopic('topic-slug1')}>Some Topic</Text>
     <Text onPress={(text) => this.setTopic('topic-slug2')}>Some Topic</Text> 
     <Text onPress={(text) => this.setTopic('topic-slug3')}>Some Topic</Text>           
    </View>
   setTopic(searchedTopic) {
    this.setState({topic: searchedTopic});
  }
这是我的api调用:

     this.state = {
      loading: false,
      dataSource: [],
      error: null,
      topic: '',
  }
   getUsers = () => {
    fetch('https://someapi.com/?topic=' + this.state.topic, {method: 'GET'}).then((response) => response.json()).then((responseJson) => {
      this.setState({
        loading: false,
        error: responseJson.error || null,
        dataSource: responseJson.data.users,
      });
    }).catch((error) => {
      this.setState({error, loading: false});
    });
  }
    <View>
     <Text onPress={(text) => this.setTopic('topic-slug1')}>Some Topic</Text>
     <Text onPress={(text) => this.setTopic('topic-slug2')}>Some Topic</Text> 
     <Text onPress={(text) => this.setTopic('topic-slug3')}>Some Topic</Text>           
    </View>
   setTopic(searchedTopic) {
    this.setState({topic: searchedTopic});
  }
这里是我在渲染方法中的主题,它工作得很好,但我需要将文本更改为复选框:

     this.state = {
      loading: false,
      dataSource: [],
      error: null,
      topic: '',
  }
   getUsers = () => {
    fetch('https://someapi.com/?topic=' + this.state.topic, {method: 'GET'}).then((response) => response.json()).then((responseJson) => {
      this.setState({
        loading: false,
        error: responseJson.error || null,
        dataSource: responseJson.data.users,
      });
    }).catch((error) => {
      this.setState({error, loading: false});
    });
  }
    <View>
     <Text onPress={(text) => this.setTopic('topic-slug1')}>Some Topic</Text>
     <Text onPress={(text) => this.setTopic('topic-slug2')}>Some Topic</Text> 
     <Text onPress={(text) => this.setTopic('topic-slug3')}>Some Topic</Text>           
    </View>
   setTopic(searchedTopic) {
    this.setState({topic: searchedTopic});
  }

我只需要使用复选框,而不是
,即可在AndroidIOS

上同时使用确保您必须根据选中的复选框添加条件为真或假

下面是一个插件演示:

构造函数(道具){
超级(道具);
此.state={
主题:空,
检查主题1:错误,
检查主题2:错误,
检查主题3:错误,
}
}
setTopic=(slug)=>{
如果(slug==“topic-slug1”){
这是我的国家({
checkTopic1:!this.state.checkTopic1
})
}else if(slug==“topic-slug2”){
这是我的国家({
checkTopic2:!this.state.checkTopic2
})
}else if(slug==“topic-slug3”){
这是我的国家({
checkTopic3:!this.state.checkTopic3
})
}
这是我的国家({
主题:鼻涕虫
})
这是getUsers();
}
getUsers=()=>{
取('https://someapi.com/?topic=“+this.state.topic,{method:'GET'})。然后((response)=>response.json())。然后((responseJson)=>{
这是我的国家({
加载:false,
错误:responseJson.error | | null,
数据源:responseJson.data.users,
});
}).catch((错误)=>{
this.setState({error,loading:false});
});
}
this.setTopic('topic-slug1')}
isChecked={this.state.checkTopic1}
leftText={“某些主题”}
/>
this.setTopic('topic-slug2')}
isChecked={this.state.checkTopic2}
leftText={“某些主题”}
/>
this.setTopic('topic-slug3')}
isChecked={this.state.checkTopic3}
leftText={“某些主题”}
/>