如何默认select第一个值?
How to select the first value by default?
我有来自 native-base 的 Picker 组件。我希望默认情况下自动选择第一个值
来自数据库 "vaccinationSchemas" 即将到来。我希望数据被选中。
let vacineFormData: any = {
id: generateUUID(),
medicineId: "",
animalId: "",
diseaseId: "",
taskId: "",
analysisTubeId: "",
eventDate: new Date(),
vaccinationSchemaId: "",
};
vacineFormPropUpdate(prop: string, value: any) {
const { vacineFormData } = this.state;
this.setState({
vacineFormData: {
...vacineFormData,
[prop]: value,
},
});
}
const schemasData = vaccinationSchemas.map(v=>({
label:v.id,
value:v.id
}))
<Picker
data={schemasData}
value={vacineFormData.vaccinationSchemaId}
onValueChange={v =>
this.vacineFormPropUpdate("vaccinationSchemaId",v)}
placeholder={t("global_vaccination_schemas")}
/>
handleChangeOption(val) {
if (val !== 0) {
this.setState({selectedValue: val});
}
}
<View style={Styles.row}>
<Picker
selectedValue={this.state.selectedValue}
onValueChange={this.handleChangeOption}
>
{schemasData.map(item=>
<Picker.Item label={item.label} value={item.value} />)
}
</Picker>
</View>
我有来自 native-base 的 Picker 组件。我希望默认情况下自动选择第一个值
来自数据库 "vaccinationSchemas" 即将到来。我希望数据被选中。
let vacineFormData: any = {
id: generateUUID(),
medicineId: "",
animalId: "",
diseaseId: "",
taskId: "",
analysisTubeId: "",
eventDate: new Date(),
vaccinationSchemaId: "",
};
vacineFormPropUpdate(prop: string, value: any) {
const { vacineFormData } = this.state;
this.setState({
vacineFormData: {
...vacineFormData,
[prop]: value,
},
});
}
const schemasData = vaccinationSchemas.map(v=>({
label:v.id,
value:v.id
}))
<Picker
data={schemasData}
value={vacineFormData.vaccinationSchemaId}
onValueChange={v =>
this.vacineFormPropUpdate("vaccinationSchemaId",v)}
placeholder={t("global_vaccination_schemas")}
/>
handleChangeOption(val) {
if (val !== 0) {
this.setState({selectedValue: val});
}
}
<View style={Styles.row}>
<Picker
selectedValue={this.state.selectedValue}
onValueChange={this.handleChangeOption}
>
{schemasData.map(item=>
<Picker.Item label={item.label} value={item.value} />)
}
</Picker>
</View>