简体   繁体   English

Map 不是 Objects React 中的 arrays 中的 function

[英]Map is not a function in arrays inside Objects React

Im getting Map is not a function in arrays inside Objects in React,我得到的 Map 不是 React 对象中 arrays 中的 function,

Here is my code:这是我的代码:

export const detailProduct = [

    {
        sku: "price_1HCCiwLjQjzuYZ7H4KhpEqLX",
        title: "Tibetan Singing Bowl Set",
        price: 29.99,
        info: "Tibetan Singing Bowl Set Meditation Bowl",
        madeInfo: "3.2 Handmade Meditation Bowl x 1, Hand- sewn Silk Cushion x 1, Mallet covered with leather x 1, creamy white storage bag x 1.A full set of Tibetan Meditation Yoga Singing Bowl with decent price. Our singing bowl can fit in your hand, portable and perfect for on - the - go requirements. CRAFTSMANSHIP - Hand hammered by the craftsmen specializing in Meditation Yoga Singing Bowls.Well - carved symbols and vivid patterns revealed the wholehearted process.Specially hand - sewn silk cushion highlighted the quality of the singing bowl set.",
        typeInfo: "PREMIUM QUALITY - Adopting traditional Nepalese craft, made up of seven metals including gold, silver, mercury, copper, iron, tin and lead.",
        moreInfo: "EASY TO USE - You can gently tap the mallet to the outside and inside edges of the meditation bowl or play it around the rim to produce the resonant sounds and deep vibrations that can relax your mind and release stress. WIDE APPLICATIONS - Great choice for yoga meditation, sound therapy, spiritual gatherings and stress relief. Ideal for healing from stress disorders, pain, depression and excessive lust. Perfect gifts for your friends, families and sweetheart.",
        inCart: false,
        images: [

            {
                url: "/singingbowl2999/1.png"
            },
            {
                url: "/singingbowl2999/2.png"
            }

        ]



    }

]

I am having trouble looping over Images array.我在遍历 Images 数组时遇到问题。 I get map is not a function. Please help我得到 map 不是 function。请帮助

try doing尝试做

detailProduct[0].images.map(image => { 
  // do what you want in here.
})

My best guess is that you forgot to specify the index in the detailProduct array.我最好的猜测是您忘记在 detailProduct 数组中指定索引。 The images you want to access are a part of the object which is at index 0 in the detailProduct array.您要访问的图像是 object 的一部分,它位于detailProduct数组中的索引 0 处。

Try the following:尝试以下操作:

detailProduct[0].images.map((image, index) => { 
  <img key={index} src={require(image.url)} />
})

thank you all I got it.谢谢大家,我明白了。 I was doing some tutorial and wanted add extra images.我正在做一些教程,想添加额外的图像。 I got it.我知道了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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