생활
html에서 if문 사용하고있습니다.
nodejs mongoDB 사용중입니다.
DB값을 변수?에 담아서 html로 담긴값을 if문으로 판단해서 출력해서 보여주고 싶습니다.
(if문만 제거하면 값이 잘 출력되는 것으로 확인이되었습니다.)
1. 아래는 html(ejs부분입니다.) if문이 잘못된거 같아요.
<% for (const p of posts) { %> <% if(p.category == "test11_board") { %> <li class="list-group-item"> <a href="/test11_board/view/<%= p._id %>"> <%= p.title %> / <%= p.username %> / <%= p.created_at_format%> </a> </li> <% } %> <% } %>2. js
boards에 저장글 내용이 들어 있습니다.
const Test11BoardService = require('../service/test11_board_service'); // html-entities module is required in showpost.ejs const main_listpost3 = async function(req, res) { const { boards, totalCnt, totalPage } = await Test11BoardService.findTest11BoardListWithPaging(1, 5, null, null); var context = { title: 'Test11글 목록', posts: boards, page: 1, pageCount: 5, perPage: 5, totalRecords: 5, size: 5 }; res.render('index', context); };