mongoDB와 nodeJS 응용 프로그램에 문제가 있습니다. 포럼을 만들려고하고 각 항목마다 단추가 모든 하위 항목을 표시하도록합니다. 그래서 내가 요청에 모든 것을 얻을해야합니다 주요 주제와MongoDB 요청에서 extern 변수에 액세스하여 수정하십시오.
- 한 배열 매핑없이
- [ '항목 1'] 포함하는 또 다른지도 배열이 하위 주제
(실제 문제가 아님)이 있습니다 :
Post.find({'path': path})
.exec(function (err, posts){
if(err)
console.log("Get post list:" + err);
else
{
var sub_posts = new Array; // Second array with sub topics
for (var i = 0; posts[i]; i++) //Here is the loop for each topic
{
var tmp_path = ... // Path and next request works
Post.find({'path': tmp_path}) // Here is the second request
.exec(function(err, bis_posts) {
if (err) console.log('Error loading subforum');
else sub_posts.push(bis_posts); // Affectation fail !!!
})
}
res.render(... 'post_list': posts, 'sub_posts': sub_posts); // Send result
}
})}
그것은 범위 문제와 내가 콜백을 사용해야하지만 루프와 함께이 문제를 해결할 수 없습니다.
영어로 감사드립니다. 답변 해 주셔서 감사합니다.
영향을받지는 못했지만 그 다음에 sub_post를 얻을 수 없습니다. 하지만 지금은 논리를 이해하고 답을 주셔서 감사합니다! – Leeios