[英]React native material dropdown pass api data
React native material drop-down passing API data I have array of data-list userTypes.反应原生材料下拉传递 API 数据我有数据列表 userTypes 数组。 I am trying to render userTypes array data userName in drop-down.
我正在尝试在下拉列表中呈现 userTypes 数组数据 userName。
constructor(){
super()
this.state ={
bookingLists:[],
userTypes: [{userType: 'admin', userName: 'Admin User'}, {userType: 'employee', userName: 'Employee User'}, {userType: 'dev', userName: 'Developer User'}]
}
}
I just wanted to know how to render userName in dropdown data field我只是想知道如何在下拉数据字段中呈现 userName
<View style={{ width: 200, marginTop: -15, justifyContent: 'flex-start',}}>
<Dropdown
label=''
value="Pure Austin Fitness"
data={this.state.userTypes.userName}
baseColor="#fff"
textColor="#fff"
itemColor="#000"
selectedItemColor="#000"
fontSize={18}
dropdownPosition={0}
/>
</View>
I think the data props in dropdown expects a js array as it's value.我认为下拉列表中的数据道具需要一个 js 数组作为它的值。 You have given a undefined object as it's value.
你给了一个未定义的对象作为它的值。 ie
data={this.state.userTypes.userName}
.即
data={this.state.userTypes.userName}
。 You should probably do data={this.state.userTypes}
.你可能应该做
data={this.state.userTypes}
。 Also I think the library requires the data to be in format { value: 'admin', label: 'Admin user' },
另外我认为图书馆要求数据的格式为
{ value: 'admin', label: 'Admin user' },
var tempMarker = [];
for (var p in userTypes) {
tempMarker.push({
value: userTypes[p].userName
});
}
this.setState({sampleState: tempMarker });
please take sampleState as a state in constructor and load the data in DropDown.请在构造函数中将 sampleState 作为状态并在 DropDown 中加载数据。
<View style={{ width: 200, marginTop: -15, justifyContent: 'flex-start',}}>
<Dropdown
label=''
value="Pure Austin Fitness"
data={this.state.userTypes.sampleState}
baseColor="#fff"
textColor="#fff"
itemColor="#000"
selectedItemColor="#000"
fontSize={18}
dropdownPosition={0}
/>
</View>
Hope this will be helpful.希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.