将JSON数据嵌套到EJS模板节点Js

时间:2018-12-10 11:13:49

标签: node.js json express ejs

如何遍历嵌套的JSON数据?我需要知道编码的正确方法。我这里有一些未完成的代码,我只是不明白如何在JSON文件中的节点js中循环。

  

EJS模板

<% for (x in schedData) { %>
<label>Employee ID:</label>
<p><%- x %></p><br>
<% } %>

<label>Employee Name:</label>
<% for (n in schedData[x]) {%>
<p><%- schedData[x][n].employee_name %></p><br>
    <% } %>
<table style="Border: 1px solid black">
    <tr>

        <th>Date</th>
        <th>Time In</th>
        <th>Time Out</th>
        <th>Schedule Shift In</th>
        <th>Schedule Shift Out</th>
        <th>Total Hours</th>
        <th>Considered Hours</th>
        <th>Break Duration (Hrs)</th>
        <th>Break Instance</th>
        <th>Late (Mins)</th>
        <th>Undertime (Mins)</th>
        <th>Reg OT (Hrs)</th>
    </tr>
    <tr>

            <% for (y in schedData) {%>
        <td><%- Object.keys(schedData[y].date_log) %></td>
        <% } %>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>

    </tr>

</table>

我不确定我是否正确输入。

  

JSON文件

{"652":
    {"employee_info":
            {"employee_name":"Byron Mataya"},
        "date_log":
            {
                "2017-12-31":
                {
                    "config":{
                        "shift":"R","hours_per_day":8,
                        "break_hours":1,"flexi_hours":0,
                        "grace_period":15
                    },
                    "log":{
                        "time_in":"2017-12-31 07:35:37",
                        "time_out":"2017-12-31 09:34:01",
                        "break_out":["2017-12-31 12:00:00"],
                        "break_in":["2017-12-31 13:00:00"],
                        "shift_in":"2017-12-31 16:00:00",
                        "shift_out":"2017-12-31 16:00:00",
                        "status":"present",
                        "holiday":"no",
                        "overtime":"no"}
                },
                "2017-12-29":
                    {
                        "config":{
                            "shift":"FL",
                            "hours_per_day":8,
                            "break_hours":1,
                            "flexi_hours":2,
                            "grace_period":0},
                        "log":{
                            "time_in":"2017-12-29 00:20:00",
                            "time_out":"2017-12-29 10:35:00",
                            "break_out":["2017-12-31 12:00:00"],
                            "break_in":["2017-12-31 13:00:00"],
                            "shift_in":"2017-12-29 16:00:00",
                            "shift_out":"2017-12-29 16:00:00",
                            "status":"present",
                            "holiday":"no",
                            "overtime":"no"
                    }
                },
                "2017-12-28":
                    {
                        "config":{
                            "shift":"R",
                            "hours_per_day":8,
                            "break_hours":1,
                            "flexi_hours":0,
                            "grace_period":0},
                        "log":{
                            "time_in":"2017-12-28 00:02:25",
                            "time_out":"2017-12-29 10:35:00",
                            "break_out":["2017-12-31 12:00:00"],
                            "break_in":["2017-12-31 13:00:00"],
                            "shift_in":"2017-12-28 16:00:00",
                            "shift_out":"2017-12-28 16:00:00",
                            "status":"present",
                            "holiday":"no",
                            "overtime":"no"
                            }}
                    }
                }

}

从json文件中获取所有数据非常令人困惑。

Here is my output showing some details coming off from json file, using express js

0 个答案:

没有答案