在React Native中如何从JSON数组动态获取Flatlist中的密钥

时间:2018-09-07 06:58:37

标签: javascript react-native

内部平面列表如何从JSON数据动态传递密钥

 Data:[{b:'1',c:'2',d:'3',e:'4'},                 
{b:'5',c:'6',d:'7',e:'8'}]



<Text style={{padding:10}}>{item.b}</Text>)}/>

1 个答案:

答案 0 :(得分:0)

import { FlatList } from 'react-native'; // Import FlatList

let data = [{b:'1',c:'2',d:'3',e:'4'},{b:'5',c:'6',d:'7',e:'8'}]; // Declare your array.

// Add FlatList into your view
<FlatList
   data={data}
   renderItem={this.renderListItem}
   keyExtractor={(item, index) => index.toString()}
/>

// In renderListItem, each object in the array will be passed in as a parameter.
renderListItem = ({ item }) => (
   <Text style={{padding:10}}>{item.b}</Text>)}/>
);