简体   繁体   中英

How to show list of array data with a dynamic name in a flatlist with react native?

how to a render list of array data that has a dynamic name in a flatlist with react native?

this is the list of data below i would like to display in the flatlist

const movies = [
  {
    '4W2JJ0CLbvfLJzBUHORVaz6sAGv2': [
      {
        name: 'crystal',
        showWatched: 'cars',
        number: 1,
      },
      {
        name: 'barbra',
        showWatched: 'sunshine',
        number: 2,
      },
    ],
  },
];

the dynamic name is '4W2JJ0CLbvfLJzBUHORVaz6sAGv2' i tried this below but noting isn't showing



  render() {
    const data = '4W2JJ0CLbvfLJzBUHORVaz6sAGv2';
    return (
      <FlatList
        data={movies[0].data}
        renderItem={({ item }) => {
          return (
            <View>
              <Text style={{ fontSize: 16 }}>{item.name}</Text>
              <Text style={{ fontSize: 16 }}>{item.showWatched}</Text>
              <Text style={{ fontSize: 16 }}>{item.number}</Text>
            </View>
          );
        }}
      />
    );
  }

Please try
data={movies[0][data]}

For dynamic key, you should use bracket [key]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM