我有一些对象,如下例所示;
[{ "id" : 13100,"key" : "Emlak Vergisi","y" : 135638.98 },{ "id" : 13154,"key" : "Çevre Temizlik ","y" : 956.17 },{ "id" : 19998,"key" : "Genel Tahakkuk","y" : 89030.62 },{ "id" : 24998,"key" : "Gecekondu ve So","y" : 42721.07 },{ "id" : 60000,"key" : "Ortak Gelirler","y" : 827.42 } ]
是否可以为每个项目设置一个带有交替颜色的列表视图?
解决方法
我会说这种方法更清洁:
renderRow(rowData,sectionID,rowID) { let style = [ styles.row,{'backgroundColor': colors[rowID % colors.length]} ]; return (<View style={style}/>); } let colors = ['#123456','#654321','#fdecba','#abcdef']; let styles = StyleSheet.create({ row: { // .. rows style } });