这是我的反应本机选择器的代码。 我想获取所选 json 数组的所有值。
我想提供多项选择。
<Picker
mode="dropdown"
style={styles.droplist}
selectedValue={this.state.mode}
onValueChange={this.funcValueChanged}>
<Picker.Item label="Select Company" value="Select Company" />
{
this.state.data.map((item, key) => (
<Picker.Item
label={item.Co_Name + ' (' + item.CompCode + ')'}
value={key}
key={key}
/>
)))
}
</Picker>
您可以用于单选/多选
从“react-native-dropdown-picker”导入 DropDownPicker;
<DropDownPicker
items={getAllStates}
searchable={true}
searchablePlaceholder="Search for an item"
searchablePlaceholderTextColor="gray"
placeholder="Select States"
placeholderTextColor={"grey"}
multiple={true}
multipleText="%d items have been selected."
containerStyle={{ marginTop: 8, marginBottom: 8, width:
"92%", alignSelf: "center", }}
onChangeItem={item => {
}
} />
尝试这个轻量级且完全可定制的包
**rn-multipicker**
- https://www.npmjs.com/package/rn-multipicker
完整文章:https://dev.to/rahul04/add-multi-select-dropdown-to-react-native-applications-53ef