【发布时间】:2020-06-24 18:07:13
【问题描述】:
我在从后端获取数据 API 时尝试实现一个复选框,但我遇到的问题是所有复选框都已选中,我无法取消选中它,以及如何通过选中的复选框作为下一个组件的参数。 我希望我能得到一些帮助。
这是我当前代码中的内容;
class Gifts extends Component {
constructor(props){
super(props);
this.state={
users:'',
checked: {},
selected: 0
}
}
句柄复选框的API代码
handleChange = (index) => {
let { checked } = this.state;
checked[index] = !checked[index];
this.setState({ checked });
}
onPress(value) {
this.setState({ selected: value });
}
render() {
let { navigation } = this.props
return (
<SafeAreaView style={{flex:1 }}>
<View style={{ flex:1,justifyContent: 'center'}}>
//...codes..//
<View style={styles.userlist}>
<FlatList
data={this.state.users}
keyExtractor={(item ,index) => index.toString()}
renderItem={({ item }) => (
<FlatList
data={item.friendList}
renderItem={({ item }) =>
<View style= {{flexDirection:'row', justifyContent:'space-between'}}>
<Text style={{marginTop:20, marginLeft:10, fontSize: 20}}>{item.name}</Text>
<CheckBox
center
checkedIcon='dot-circle-o'
uncheckedIcon='circle-o'
checked={this.state.checked}
value={ this.state.checked[item.flag]}
onPress={this.onPress}
/>
</View>
}
keyExtractor={(item ,index) => index.toString()}
ItemSeparatorComponent ={this.ItemSeparator}
/>
)}
/>
</View>
<Button
rounded
// disabled={true}
//onPress={}
style={{width: 100, justifyContent: 'center',marginLeft:150}}
>
<Text>Send</Text>
</Button>
</View>
</SafeAreaView>
);
}
}
【问题讨论】:
标签: android ios react-native mobile-application mobile-development