我希望能够在我的 expo React 本机应用程序中添加多个复选框。我在下面提供相关代码。我的类中有一个数组,其中包含有关复选框的详细信息,它有一个 id、必须旁边的文本以及检查该复选框是否被选中的检查。
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0,
inputTxt: "",
checks: [
{id: 1, txt: "first check", isChecked: false },
{id: 2, txt: "second check", isChecked: false }
]
};
}
render() {
return (
<View style={styles.container}>
<Text style={styles.text}>Details Screen</Text>
<View>
<View style={styles.checkboxContainer}>
<CheckBox/>
{/* Add all the checkboxes from my this.state.checks array here */}
<Text style={styles.label}>Do you like React Native?</Text>
</View>
</View>
[...]
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)