Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
52 views
in Technique[技术] by (71.8m points)

javascript - Mapping multiple Array in React

I am trying to achieve this : To achieve

While trying, I created an JavaScript Object(JSON like object) to access it. Here's the code:

export default [
    {
        weekMonth: 'February',
        weekDayofWeek: ['Thur', 'Thur', 'Thur', 'Thur'],
        weekDays: [ '04', '11', '18', '25'],
        weekStatus: 'Available +',
        className: 'February'
    },
    
    {
        weekMonth: 'March',
        weekDayofWeek: ['Thur', 'Thur', 'Thur', 'Thur'],
        weekDays: [ '04', '11', '18', '25'],
        weekStatus: 'Available +',
        className: 'March'
    },

    {
        weekMonth: 'April',
        weekDayofWeek: ['Thur', 'Thur', 'Thur', 'Thur', 'Thur'],
        weekDays: [ '01', '08', '15', '22', '29' ],
        weekStatus: 'Available +',
        className: 'April'
    },

    {
        weekMonth: 'May',
        weekDayofWeek: ['Thur', 'Thur', 'Thur', 'Thur'],
        weekDays: [ '06', '13', '20', '27' ],
        weekStatus: 'Available +',
        className: 'May'
    }
];

Now, I'm trying to access each data in object file to get the desired result showed in the image but it's not working well.

How I rendered it:

import Col from "react-bootstrap/Col";
import Card from 'react-bootstrap/Card';

const Weekitem = ({
    weekMonth, weekDayofWeek, weekDays, weekStatus, className
}) => {
    return ( 
        <>
            <Col lg={3} md={3} sm={6} xs={12}>
                <h3> {weekMonth} </h3>
                    {weekDays.map((weekday) => (
                        <Card>
                            <h1> {weekday} </h1>
                            {weekDayofWeek}
                            {weekStatus}
                        </Card>
                    ))}
            </Col>
        </>
     );
}
 
export default Weekitem;

Then, I got this: gotten

What could be error? Please, check. But h1 worked as expected. Why other? Thanks.

question from:https://stackoverflow.com/questions/65936442/mapping-multiple-array-in-react

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...