2012-01-05 4 views
0

내가 app.js스토어 변수 몽구스와 쿼리 후 데이터와

var Song = db.model('Song'); 
    var Album = db.model('Album'); 

내가이 개 변수 index.jade에 렌더링 할 코드를 Node.js를가 list of songlist of album
있습니다 나는이

Song.find({}, function(err, docs){ 
// ......... 
} 
Album.find({}, function(err, docs){ 
// ......... 
} 
같은 쿼리를 사용하여

list of songlist of albumvariables에 저장하고 index.jade을 2 목록으로 렌더링하려면 어떻게해야합니까? 의

답변

1

나는이 같은 것을 의미 생각 :

function(req, res) { // whatever your "controller" function is 
    Song.find({}, function(err, songs){ 
    Album.find({}, function(err, albums){ 
     res.render('index', { song_list: songs, album_list: albums }); 
    }); 
    }); 
} 

가 그럼 그냥 반복하고 템플릿에 song_listalbum_list 배열을 마크 업.

동기식이므로 비동기 방식보다 느리지 만 원하는대로 처리해야합니다. 비동기 경로로 이동하려면 다음과 같이 라이브러리를 사용하여 res.render을 연기하십시오. https://github.com/kriszyp/promised-io

+0

안녕하세요, Jed, 제가 여기에서 문제를 해결하는 데 도움을 줄 수 있습니까? (http://stackoverflow.com/questions)/8754597/store-data-to-store-connection-redis) –