簡體   English   中英

Map 不是 Objects React 中的 arrays 中的 function

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

我得到的 Map 不是 React 對象中 arrays 中的 function,

這是我的代碼:

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"
            }

        ]



    }

]

我在遍歷 Images 數組時遇到問題。 我得到 map 不是 function。請幫助

嘗試做

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

我最好的猜測是您忘記在 detailProduct 數組中指定索引。 您要訪問的圖像是 object 的一部分,它位於detailProduct數組中的索引 0 處。

嘗試以下操作:

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

謝謝大家,我明白了。 我正在做一些教程,想添加額外的圖像。 我知道了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM