英文:
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 :
<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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论