【问题标题】:In React Native how to get key in flatlist dynamically from json array在 React Native 中,如何从 json 数组中动态获取 flatlist 中的键
【发布时间】:2018-09-07 06:58:36
【问题描述】:

在平面列表中如何从 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>)}/>

【问题讨论】:

  • 你试过什么?至少展示你做过的事情

标签: javascript react-native


【解决方案1】:
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>)}/>
);

【讨论】:

    猜你喜欢
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 2022-01-25
    • 2021-10-19
    • 2018-08-28
    • 1970-01-01
    相关资源
    最近更新 更多