数组不是子映射数组中的本机反应函数

时间:2020-01-15 11:59:19

标签: arrays react-native

这是我调用对象数组的代码

 {data.map((item, index ) =>
        <View>
        <Text key={index}>{item.type}</Text>

        {item.resultlist((sub,index)=>

            <Text key={index}>{sub.name}</Text>

          )}
            </View>
    )}

这是我对json数组的响应

 {
"status": "success",
"message": "Home page Response",
"response": [
    {
        "type": "product",
        "status": true,
        "sort_order": 0,
        "resultlist": [
            {
                "name": "Mifa F1",
                "img": "https://www.achhacart.com/image/cache/catalog/new%20thumbnails/Mifa%20A1BlacjkThumbnail-600x600.jpg",
                "type": "product",
                "product_id": 87
            },
            {
                "name": "Earphone",
                "img": "https://www.achhacart.com/image/catalog/cmsblock/hgb5.png",
                "type": "category",
                "category_id": 20
            },
            {
                "name": "Air Purifier",
                "img": "https://www.achhacart.com/image/catalog/cmsblock/air.gif",
                "type": "product",
                "product_id": 87
            },
            {
                "name": "Powerbank",
                "img": "https://www.achhacart.com/image/catalog/cmsblock/Powerbank10.jpg",
                "type": "product",
                "product_id": 87
            }
        ]
    },
    {
        "type": "middleimage",
        "status": true,
        "sort_order": 1,
        "img": "https://www.achhacart.com/image/catalog/cmsblock/Powerbank10.jpg",
        "product_id": 187
    },
    {
        "type": "product",
        "status": true,
        "sort_order": 2,
        "resultlist": [
            {
                "name": "Mifa A1 Black",
                "img": "https://www.achhacart.com/image/cache/catalog/new%20thumbnails/Mifa%20A1BlacjkThumbnail-600x600.jpg",
                "type": "product",
                "product_id": 87
            },
            {
                "name": "Earphones",
                "img": "https://www.achhacart.com/image/catalog/cmsblock/hgb5.png",
                "type": "category",
                "category_id": 20
            },
            {
                "name": "Air Purifiers",
                "img": "https://www.achhacart.com/image/catalog/cmsblock/air.gif",
                "type": "product",
                "product_id": 87
            },
            {
                "name": "Powerbanks",
                "img": "https://www.achhacart.com/image/catalog/cmsblock/Powerbank10.jpg",
                "type": "product",
                "product_id": 87
            }
        ]
    },
    {
        "type": "slider",
        "status": true,
        "sort_order": 3,
        "resultlist": [
            {
                "title": "slider1",
                "link": "",
                "image": "https://www.achhamall.com/staging-achhamall.com/image/catalog/1AA/WeChatImage_20191228151402.jpg"
            },
            {
                "title": "slider2",
                "link": "",
                "image": "https://www.achhamall.com/staging-achhamall.com/image/catalog/1accc/WeChatImage_20191231125513.jpg"
            }
        ]
    }
]

}

我应如何在本地本机中调用整个数组函数中的子数组,我正在使用map函数,但错误仍然相同 当我在数组对象之外调用数组对象时,其渲染 建议我哪里错了

2 个答案:

答案 0 :(得分:2)

当您尝试遍历 npm install ng build --prod 时,它的外观使您错过了map

resultlist-> item.resultlist

似乎item.resultlist.map((sub, index) => { ... }中的每个item都不包含data,所以也许检查一下它是否也存在。

答案 1 :(得分:1)

有两件事 1)首先,Yoo还必须在您的子数组中应用map 2)您不返回标签元素。

使用以下代码

{data.map((item, index ) =>
    return (
        <View>
            <Text key={index}>{item.type}</Text>
            {item.resultlist.map((sub,index)=>
       return (
                    <Text key={index}>{sub.name}</Text>
                )
            )}
        </View>
    );
)}