이것은 어리석은 질문 일 수도 있지만 학교에서 아무도 그렇게하는 방법을 모르는 사람입니다. 완벽하게 작동하는 코드가 있습니다 (객체 테이블 potentials
을 전송하고 클라이언트 측에서도이 코드를 사용할 수 있습니다).하지만 다른 것을 필요로한다는 것을 기억했습니다 (userData
). 그래서 나는 이것을 const
으로 선언하고 나서 내 res.render
직전에 로깅하려고 시도했지만 undefined
입니다. 우리 그룹의 학생들은 지금까지 약속을 잘 모르며, 그래서 우리는 뭔가를 놓치고 있습니다. 어쨌든 여기 내 코드, 어떤 도움 ?? 고맙습니다. 당신은 올바른 방법으로 Promise
사용하지 않는이 약속의 가치를 되 찾으십시오.
function matchaSearch (pool, username) {
return suggestUsers(pool, username)
.then((searcherInfos) => {
userData = [...searcherInfos]
if (userData[0].sex === 'm' && userData[0].orientation === 's') {
return lookForSF(pool, username)
} else if ((userData[0].sex) && userData[0].orientation === 'b') {
return lookForbothCauseImB(pool, username)
} else if ((userData[0].sex) === 'f' && userData[0].orientation === 's') {
return lookForSM(pool, username)
} else if ((userData[0].sex) === 'm' && userData[0].orientation === 'g') {
return lookForGM(pool, username)
} else if ((userData[0].sex) === 'f' && userData[0].orientation === 'g') {
return lookforGF(pool, username)
}
})
.then((rows) => {
var potentials = rows;
return (potentials)
})
}
router.post('/matchaSearch', function (req, res) {
const userData = []
matchaSearch(pool, session.uniqueID)
.then((potentials) => {
console.log(userData);
res.render('./userMatch', {potentials, userData})
})
.catch((err) => {
console.error('error', err)
res.status(500).send("we don't have any suggestions for you so far")
})
})
'userData'는 하늘의 배열은? – guest271314
실제로 나는 방금 대답을 찾았습니다. 게시 죄송합니다. res.render 바로 전에 변수에서 함수를 호출 한 다음 이동할 수 있습니다. – pkerckho
질문에 대한 답변을 얻었습니까? – jfriend00