I am using following dropdown in react native : react-native-selectme
render() {
return (
<View style={{justifyContent: 'center', alignItems: 'center'}}>
<Select width={250} ref="SELECT1" optionListRef={this._getOptionList.bind(this)} defaultValue="Select a Province in Canada ..." onSelect={this._selectItem.bind(this)}>
<Option value={ {id : "alberta"}}>Alberta</Option>
<Option>British Columbia</Option>
<Option>Manitoba</Option>
<Option>New Brunswick</Option>
<Option>Newfoundland and Labrador</Option>
<Option>Northwest Territories</Option>
<Option>Nova Scotia</Option>
<Option>Nunavut</Option>
<Option>Ontario</Option>
<Option>Prince Edward Island</Option>
<Option>Quebec</Option>
<Option>Saskatchewan</Option>
<Option>Yukon</Option>
</Select>
<Text>Selected Canadas province: {this.state.selected_value}</Text>
<OptionList ref="OPTIONLIST" />
</View>
);
}
};
But here optionList
is hardcoded. I want to add my array
into this dropdown
.
Array:
tempArray: [{
vehicle_no: 'M111',
vehicle_id: 111
}, {
vehicle_no: 'M222',
vehicle_id: 222
}]
I am new to react-native
, please guide me for better solution.
Have you tried to map your array ? Something like:
<Select .....>
{
tempArray.map(item => {
return(
<Option value={item.vehicle_id}>{item.vehicle_no}</Option>
)
});
}
</Select>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.