Create table to arrange json array using for statement

Asked 1 years ago, Updated 1 years ago, 425 views

Hello, I'm confused about the For Moon.

Currently, we are implementing a table using json data.

let monthPrint = [
    { { SelectedDate: '2022-12-01' },
    { { SelectedDate: '2022-12-02' },
    /* ... */
    { { SelectedDate: '2022-12-31' }
];

let itemCountList = [
    { { Itemdate: '2022-12-09', Itemcounta: '4', Itemcountc: '0' },
    { { Itemdate: '2022-12-19', Itemcounta: '0', Itemcountc: '5' },
    { { Itemdate: '2022-12-20', Itemcounta: '0', Itemcountc: '5' },
    { { Itemdate: '2022-12-21', Itemcounta: '0', Itemcountc: '5' },
    { { Itemdate: '2022-12-22', Itemcounta: '0', Itemcountc: '5' },
    { { Itemdate: '2022-12-23', Itemcounta: '0', Itemcountc: '4' },
    { { Itemdate: '2022-12-26', Itemcounta: '0', Itemcountc: '5' }
];

let items = ['Itemcounta', 'Itemcountc'];

In this way, monthPrint.SelectedDate and itemCountList.Itemdate If the date is the same
I'd like to list itemcounta and itemcountc by the number of items (2). If the date is different, I'd like to add -'.

    for (var i = 0; i < monthPrint.length; i++) {
        ExcelTable += '<tr><td>' + monthPrint[i].SelectedDate.substr(5, 10) + '</td>';
        for (var j = 0; j < itemCountList.length; j++) {

            if (monthPrint[i].SelectedDate.substr(5, 10) == itemCountList[j].Itemdate.substr(5, 10)) {
                for (var k = 0; k < items.length; k++) {

                    ExcelTable += '<td>' + itemCountList[j][items[k]] + '</td>';
                }
                ExcelTable += '</tr>';
            } } else {

            }
        }
    }

Even if you continue in the else part, compare it by the number of days in the itemCountList

All six are printed out like this. I tried to hold it for 3 days, but it didn't work. Please...

javascript

2022-12-27 10:24

1 Answers

I don't know if I understand it well, but if you look at the horizontal and vertical lines of the table, actually double-circuits are monthPrint and items. The former row corresponds to the tr tag, the latter corresponds to the column td tag.

Then, based on monthPrint.SelectedDate and items[x] given on this tour, is there anything to bring out of itemCountList?"You can determine and do what you need to do. In short, itemCountList is the target data for the tour process, not the standard for the tour.

That's all I have to say. Good luck to you.


2022-12-27 15:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.