如何通过嵌套的map函数获取no_images / images

时间:2019-04-01 09:47:31

标签: react-native

我想使用嵌套地图功能从no_images获取图像。

我已经尝试过,但是无法获取数据

{this.state.safetyData.map((item, key)=>{
   return(     
     <View>
       {item.no_images.map((image,key) => {
         return(
           <View>
             <Text>{JSON.stringify(image.id)}</Text>
           </View>
         )}
       )}
     </View>
  )}
)}

JSON数据为:

[
  {
    "total_count": 12
  },
  {
    "no_images": [
      {
        "id": 23,
        "title": "Foundation",
        "title_phi": "pjilo",
        "description": "ok",
        "description_phi": "ok",
        "image": "1553413849ic_launcher.png",
        "type": "1",
        "image_path": "uploads/house_images",
        "created_at": "2019-03-24 07:50:49",
        "updated_at": "2019-03-28 08:51:58",
        "house_part_id": 21,
        "image_type": 0
      }
    ]
  },
  {
    "no_count": 1
  },
  {
    "percentage": 8
  }
]

1 个答案:

答案 0 :(得分:0)

在第一个if (sftp.FolderExists(sftpPath30s)) { try { var files30s = sftp.ListDirectory(sftpPath30s); if(files30s!=null) { ... } } catch (SftpPathNotFoundException) {} } 函数中,应在使用之前检查项目try { var files30s = sftp.ListDirectory(sftpPath30s); if(files30s!=null) { ... } } catch (SftpPathNotFoundException) {} 是否存在。根据您的map输出,地图中还有其他项目。

只需像使用它之前检查对象:

no_images

希望有帮助。