Text not displaying when being mapped from Array in react.

huangapple go评论69阅读模式
英文:

Text not displaying when being mapped from Array in react

问题

使用映射函数将数组中的信息显示为3层,据我所见,一切似乎没问题,但没有显示任何信息,请有人查看代码,告诉我是否有遗漏的地方。

import styled from 'styled-components'

function Plans() {

    const notePlans = [
    {
        name:"NoteZ Free",
        price:"$0",
        features: [
            "1 user per account",
            "Unlimited notes",
            "4 categories to choose from",
            "Help Support"
            ]
    },
    {
        name:"NoteZ +",
        price:"$5",
        features: [
            "2-4 users per account",
            "Unlimited notes",
            "Folder system for notes",
            "Custom categories",
            "Custom templates to choose from",
            "Help Support"
        ]
    },
    {
        name:"NoteZ Infinity",
        price:"$10",
        features: [
            "Unlimited users per account",
            "Unlimited notes",
            "Folder system for notes",
            "Custom categories",
            "Full integration with MealZ",
            "Full integration with WorkoutZ",
            "Custom templates to choose from",
            "Help Support"
        ]
    }
    ]

  return (
    <Main>
        <div className='pricing-container'>
            {notePlans.map((plan) => (
                <div className='pricing-card' key={plan.name}>
                    <h2>{plan.name}</h2>
                    <p>{plan.price}</p>
                    <ul>
                        {plan.features.map((feature,index) => (
                            <li key={index}>{feature}</li>
                        ))}
                    </ul>
                    <button>Buy Now</button>
                </div>
            ))}
        </div>
    </Main>
  )
}

const Main = styled.div`
    width:100%;

    .pricing-container{
        border:1px solid black;
        color black;
        
    }
`;



export default Plans 

我尝试在控制台报告需要键时添加键。

英文:

Used a mapping function to display information from an array into 3 tiers, from what I can see everything seems right but none of the information is being displayed, can someone look at the code and tell me if there is something that I am missing

import React from 'react'
import styled from 'styled-components'

function Plans() {

    const notePlans = [
    {
        name:"NoteZ Free",
        price:"$0",
        features: [
            "1 user per account",
            "Unlimited notes",
            "4 categories to choose from",
            "Help Support"
            ]
    },
    {
        name:"NoteZ +",
        price:"$5",
        features: [
            "2-4 users per account",
            "Unlimited notes",
            "Folder system for notes",
            "Custom categories",
            "Custom templates to choose from",
            "Help Support"
        ]
    },
    {
        name:"NoteZ Infinity",
        price:"$10",
        features: [
            "Unlimited users per account",
            "Unlimited notes",
            "Folder system for notes",
            "Custom categories",
            "Full integration with MealZ",
            "Full integration with WorkoutZ",
            "Custom templates to choose from",
            "Help Support"
        ]
    }
    ]

  return (
    <Main>
        <div className='pricing-container'>
            {notePlans.map((plan) => (
                <div className='pricing-card' key={plan.name}>
                    <h2>{plan.name}</h2>
                    <p>{plan.price}</p>
                    <ul>
                        {plan.features.map((feature,index) => (
                            <li key={index}>{feature}</li>
                        ))}
                    </ul>
                    <button>Buy Now</button>
                </div>
            ))}
        </div>
    </Main>
  )
}

const Main = styled.div`
    width:100%;

    .pricing-container{
        border:1px solid black;
        color black;
        
    }
`;



export default Plans 

I tried adding the key when the console reported an error saying that a key was needed.

答案1

得分: 1

这里是翻译好的部分:

尝试这个:

const Main = styled.div`
    width: 100%;

    .pricing-container {
        border: 1px solid black;
        color: black;
    }
`;

color 后面缺少了一个冒号 ":"
还可以在此链接中查看示例:https://codesandbox.io/s/agitated-jepsen-5zdl2y?file=/src/App.js

英文:

Try this:

const Main = styled.div`
    width:100%;

    .pricing-container{
        border:1px solid black;
        color: black;
        
    }
`;

There was a missing ":", after color.
Also it works here: https://codesandbox.io/s/agitated-jepsen-5zdl2y?file=/src/App.js

答案2

得分: 0

Try adding return statement in your map callback function like this:

<div className='pricing-container'>
    {notePlans.map((plan) => {
        return (
            <div className='pricing-card' key={plan.name}>
                <h2>{plan.name}</h2>
                <p>{plan.price}</p>
                <ul>
                    {plan.features.map((feature, index) => (
                        <li key={index}>{feature}</li>
                    ))}
                </ul>
            </div>
        );
    })}
</div>
英文:

Try adding return statement in your map callback function like this :

&lt;div className=&#39;pricing-container&#39;&gt;
        {notePlans.map((plan) =&gt; 
            return (
            &lt;div className=&#39;pricing-card&#39; key={plan.name}&gt;
                &lt;h2&gt;{plan.name}&lt;/h2&gt;
                &lt;p&gt;{plan.price}&lt;/p&gt;
                &lt;ul&gt;
                    {plan.features.map((feature,index) =&gt; (
                        &lt;li key={index}&gt;{feature}&lt;/li&gt;
                    ))}
                &lt;/ul&gt;

huangapple
  • 本文由 发表于 2023年5月6日 23:03:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189585.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定