React-native flatlist renderItem

问题描述:

我有一个数组字典。我想把所有的价值都呈现在平板上。 我尝试:
React-native flatlist renderItem

renderItem = {({}项)=> item.A.id}

但我不返回任何值。请帮帮我。感谢

ArrAccount: { 
    "A": [ 
    { 
     "id": 1, 
     "name": "Anh Tuan Nguyen", 
     "age": 28 
    }, 
    { 
     "id": 2, 
     "name": "An Nhien", 
     "age": 2 
    }, 
    ], 
    "Z": [ 
    { 
     "id": 3, 
     "name": "Thanh Tu Pham", 
     "age": 32 
    }, 
    { 
     "id": 4, 
     "name": "Tien Thanh", 
     "age": 24 
    }, 
    ] 
} 
+0

是你的问题解决了吗? –

如果你喜欢这个

this.props.myArrayAccount = { 
     ArrAccount: { 
      "A": [ 
      { 
       "id": 1, 
       "name": "Anh Tuan Nguyen", 
       "age": 28 
      }, 
      { 
       "id": 2, 
       "name": "An Nhien", 
       "age": 2 
      }, 
      ], 
      "Z": [ 
      { 
       "id": 3, 
       "name": "Thanh Tu Pham", 
       "age": 32 
      }, 
      { 
       "id": 4, 
       "name": "Tien Thanh", 
       "age": 24 
      }, 
      ] 
     } 
     } 

const myArrayAccount = this.props.myArrayAccount.ArrAccount 
const ArrAccount = Object.keys(myArrayAccount).map((key)=> myArrayAccount[key]) 

因为你propsthis.props.myArrayAccount场在其内部具有一个以上的对象,你应该首先应该map对象比映射Flatlist成分FlatList组件

您的数据应像这样:

{ArrAccount.map((item) => 
    <FlatList 
     data={item} 
     renderItem={({item}) => <Text>{item.name}</Text>} 
    /> 
) 
} 
+0

谢谢。但我想获得数组的所有值(A和Z或许多)。你有什么办法帮助我吗? –

+0

我已经更新我的答案,以获得您的对象的价值只是告诉我,如果这能解决您的问题 –

+0

感谢您的帮助! :d –

您应该使用renderItem这样的:

renderItem = {({item:data}) => <Text>data.id</Text>} 

,这将列出所有的ID。

注意:这种风格非常简单,您可以自定义物品的风格。

+0

我尝试但没有返回值。 {data.id}} /> –

+0

更新您对在完整代码问题。 –