[英]react-native-dropdown-picker changing dropdown background color by condition
We are using react-native-dropdown-picker.我们正在使用 react-native-dropdown-picker。
<DropDownPicker items={timeList.map(item => { return ({ label: item.timeslot, value: item.timeslot }) })} defaultValue={timeList[0].timeslot} placeholder={"Select date"} containerStyle={styles.dropDownContainer} itemStyle={{ justifyContent: "flex-start" }} dropDownStyle={{ backgroundColor: colors.white }} dropDownMaxHeight={hp("45%")} onChangeItem={item => timeSelected(item.value)} arrowSize={30} arrowStyle={{ position: "absolute", right: 0 }} labelStyle={{ fontSize: wp('3.5%'), fontFamily: constants.themeFont, textAlign: 'left', color: '#000', alignSelf: 'center', }} />
So the dropdown's background color has been set from 'dropDownStyle' property.所以下拉菜单的背景颜色是从“dropDownStyle”属性设置的。 I have given the color white.
我给了白色。
Let's say, in the 'timeList' (array)variable, I have a key 'enabled' (boolean value) on every object on the array.假设,在“timeList”(数组)变量中,我在数组上的每个 object 上都有一个键“启用”(布尔值)。 So I want to give different background colors for different values(true/ false) of the key 'enabled'.
所以我想为“启用”键的不同值(真/假)提供不同的背景 colors。
The 'dropDownStyle' is the common property for all the values on the dropdown. “dropDownStyle”是下拉列表中所有值的通用属性。 So how to change the background color based on every item attribute.
那么如何根据每个项目属性更改背景颜色。
{
...
containerStyle: {
backgroundColor: "#000"
},
labelStyle: {
color: "#fff"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.