본문 바로가기

내일배움캠프 노드 4기/Today I Learned

[EJS] for 문 사용해보기

서버

ordersGet = async (req, res, next) => {
    try {
      const ordersData = await this.managerService.ordersGet();
      const imsi = [
        {
          id: 20,
          content: "급해요",
          status: 0,
          customerId: 2,
          goodsId: 1,
        },
        {
          id: 10,
          content: "급해요",
          status: 0,
          customerId: 2,
          goodsId: 2,
        },
      ];
      res.render("management.ejs", { data: imsi });
    } catch (err) {
      console.log(err);
      res.status(400).json({ errorMessage: "조회 실패" });
    }
  };

orderGet 메소드에서 데이터를 보내줍니다

 

클라이언트

<div>
        <h1>주문관리</h1>
        <table>
          <th>주문번호</th>
          <th>요청사항</th>
          <th>주문현황</th>
          <th>주문자번호</th>
          <th>상품번호</th>
          <th></th>
          <% for(let i = 0; i<data.length; i++){ %>
          <tr>
            <td><%=data[i].id%></td>
            <td><%=data[i].content%></td>
            <td><%=data[i].status%></td>
            <td><%=data[i].customerId%></td>
            <td><%=data[i].goodsId%></td>
            <td>
              <button onclick="location.href='/management/order/<%=data[i].id%>'">
                상세정보
              </button>
            </td>
          </tr>
          <% } %>
        </table>
      </div>

<%  안에 for문을 작성하고   { %>                              <% 로 닫아줍니다  }%>

클라이언트에서는 보이지 않습니다.

프론트로 보는 부분