【发布时间】:2017-09-19 13:21:51
【问题描述】:
当多个列表项被选中时,如何更改它们的背景颜色?我正在使用 react-native-accordian 和 react-native-collapsible 并在内容中使用平面列表。
_renderContent(section, i, isActive)
{
//console.log("MY DATA---",section.time_slots);
return (
<List
style={inStyles.body}
containerStyle={{ borderTopWidth: 0, borderBottomWidth: 0 }}>
<FlatList
data={section.time_slots}
renderItem={
({ item,index }) =>
(
<ListItem
onPress={() => this.selectSlot(item,section.date,index)}
style = {[inStyles.list , {marginLeft : 15}, {marginRight : 5},
{backgroundColor: (this.state.selectedItem[index]) ? 'green' : 'red'}]}
title={`${item}`}
containerStyle={{ borderBottomWidth: 0 }}
/>
)
}
keyExtractor={item => section.date+item}
ItemSeparatorComponent={this.renderSeparator}
ListFooterComponent={this.renderFooter}
/>
</List>
);
}
我只想使用TouchableOpacity 动态更改列表项的样式。但做不到。
【问题讨论】:
标签: reactjs list react-native listitem react-native-flatlist