-
글쓴이글
-
2022년 4월 7일 15:41 #31333
냠냠냠참가자안녕하세요.
to do app 진행하면서 내가 쓴 to do list 만 모아보는 페이지를 만들고 있습니다.
몽고디비 post 컬렉션에 완료 라는 문서를 만들어서 완료된 to do 는 true 로 진행중인 to do는 false로 값을 저장했습니다.
완료 여부를 보여주려고 했는데 데이터를 그대로 받아오니 true false 가 나와서 if 조건문을 쓰려고 했씁니다.
my to do 리스트를 보여주는 ejs 페이지에서 자바스크립트 문법을 이용해서 값이 true 일 때는 진행 중 이라는 글자가 to do 와 함께 뜨고, false 일 때는 완료라는 글자가 to do와 함께 뜨도록 만들고 싶었는데 문법적인 오류가 있는 것 같아 도움을 요청합니다.
mytodo.ejs 에는
<div class="container">
<ul class="list-group">
<% for (var i = 0; i < myposts.length; i++){ %>
<li class="list-group-item">
<h4> 할 일 : <%= myposts[i].제목 %> </h4>
<p> 우선순위 : <%= myposts[i].우선순위 %> </p>
<p> 날짜 : <%= myposts[i].날짜 %> </p>
<% if ( %>
<%= myposts[i].완료 %>
<% == "true") { %>
<p> 완료된 할 일 </p>
<% } else{ %>
<p> 진행 중인 할 일 </p>
<% } %>
<!-- <p> 완료 : <%= myposts[i].완료 %> </p>
<p> 공개 : <%= myposts[i].공개 %> </p> -->
<p> 메모 : <%= myposts[i].메모 %> </p>
<button class="btn btn-outline-primary delete" data-id="<%= myposts[i]._id %>">삭제</button>
<!-- <button class="btn btn-outline-primary edit" data-id="<%= myposts[i]._id %>"">수정</button> -->
<button class="btn btn-outline-primary edit" onclick="location.href='/edit/<%= myposts[i]._id %>'">수정하기</a></button>
<button class="btn btn-outline-primary complete" onclick="location.href='/complete'" data-id="<%= myposts[i]._id %>"">할 일 완료</button>
</li>
<% } %>
</ul>
</div>이렇게 코드 작성했고,
server.js 에는
//나의 todo 리스트 뿌리기
app.get('/mytodo', 로그인했니, function(요청, 응답){
console.log(요청.user);
if(요청.user.id){
db.collection('post').find({작성자 : 요청.user.id}).toArray(function(에러, 결과){
console.log('db에서 작성자 찾은 결과')
console.log(결과);
console.log('아이디')
console.log(요청.user.id);
//가져온 데이터를 ejs 파일에 넣는다
응답.render('mytodo.ejs',{myposts : 결과, user : 요청.user.id});
if(에러){return console.log(에러)};
});
} else{
console.log(요청.user.id);
console.log(요청.login.id);
응답.send("<script>alert('로그인이 필요합니다.'); window.location.replace('/login');</script>"); }
})이렇게 작성했습니다.
콘솔에는
listening on 8888
{
_id: new ObjectId("62495b9101106e828c96ff38"),
id: 'love',
pw: '$2b$10$dGbuJArd4wlGB6dWduCDGePlynIgQnauxvf8NwEOXrp7tlKL/5OP.'
}
db에서 작성자 찾은 결과
[
{
_id: 4,
'작성자': 'love',
'제목': 'test - love',
'날짜': '2022-04-01',
'메모': 'love 아이디',
'우선순위': '3',
'완료': false,
'공개': false
},
{
_id: 5,
'작성자': 'love',
'제목': 'test 2 - love',
'날짜': '2022-04-01',
'메모': 'love 라는 아이디 2',
'우선순위': '1',
'완료': false,
'공개': false
},
{
_id: 6,
'작성자': 'love',
'제목': 'test 3 - love',
'날짜': '2022-04-22',
'메모': 'love 라는 아이디 3',
'우선순위': '3',
'완료': false,
'공개': false
},
{
_id: 7,
'작성자': 'love',
'제목': '커피마시기',
'날짜': '2022-04-14',
'메모': '그냥 그래',
'우선순위': '2',
'완료': true,
'공개': false
},
{
_id: 8,
'작성자': 'love',
'제목': '커피',
'날짜': '2022-04-15',
'메모': '2시 예약',
'우선순위': '2',
'완료': true,
'공개': false
}
]
아이디
love
SyntaxError: Unexpected token ';' in C:\Users\I\Desktop\todoapp\views\mytodo.ejs while compiling
If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, passasync: true
as an option.
at new Function (<anonymous>)
at Template.compile (C:\Users\I\Desktop\todoapp\node_modules\ejs\lib\ejs.js:662:12)
at Object.compile (C:\Users\I\Desktop\todoapp\node_modules\ejs\lib\ejs.js:396:16)
at handleCache (C:\Users\I\Desktop\todoapp\node_modules\ejs\lib\ejs.js:233:18)
at tryHandleCache (C:\Users\I\Desktop\todoapp\node_modules\ejs\lib\ejs.js:272:16)
at View.exports.renderFile [as engine] (C:\Users\I\Desktop\todoapp\node_modules\ejs\lib\ejs.js:489:10)
at View.render (C:\Users\I\Desktop\todoapp\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users\I\Desktop\todoapp\node_modules\express\lib\application.js:640:10)
at Function.render (C:\Users\I\Desktop\todoapp\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\Users\I\Desktop\todoapp\node_modules\express\lib\response.js:1017:7) )이렇게 출력되는 상황입니다.
제가 어떻게 코드를 고쳐야할까요??
-
글쓴이글
- 답변은 로그인 후 가능합니다.