在选择本机时,我想如何在本机选择器中创建数组,如果选择了值,我想这样做
state = { selected: null, arr: [] }
<Picker
selectedValue={selected}
style={{ height: 20, width: 110 }}
onValueChange={(itemValue, itemIndex) => {
this.setState({ selected: itemValue })
this.state.arr.push(selected)
}}
>
{dummy.map((val, idx) => (
<Picker.Item label={val.attendance} value={val.id} key={idx} />
))}
</Picker>
如果我选择value = ['present','present','sick',离开']
答案 0 :(得分:0)
尝试一下
<Picker
selectedValue={selected}
style={{ height: 20, width: 110 }}
onValueChange={(itemValue, itemIndex) => {
this.setState({
selected: itemValue,
arr: [...this.state.arr].push(selected)
})
}}
>