2015-06-28 63 views
0

如果我做以下搜索:如何通過迭代對象的集合流星蒙戈內

VideoCourses.find({'_id': 'jkwehrjewrew'}).fetch()[0].videos 

我得到如下:

Object {first: "firstvideo.html", second: "secondvideo.html", third: "thirdvideo.html"} 

我的問題,是通過收集如何可以迭代。我想一次渲染一個視頻,所以我可以渲染第一個視頻,然後點擊,渲染第二個,等等。

事情是,我有很多套視頻,所以這應該是動態完成的。它應該迭代通過下一個video.first,video.second ..等

這可能嗎?我研究過.next(),但我認爲這適用於整個集合,而不是集合內的對象。

預先感謝您!

+1

你試過了什麼?你可以顯示你的模板+幫助代碼,哪些不起作用,這樣我們有一個起點? –

回答

1

這是一個JavaScript問題,不一定是流星。使用for-in循環遍歷對象。

// This query returns an object 
var MyObject = VideoCourses.find({'_id': 'jkwehrjewrew'}).fetch()[0].videos 

// The object is brings back looks like this: 
// {  
// first: "firstvideo.html", 
// second: "secondvideo.html", 
// third: "thirdvideo.html" 
// }; 


// Use a for-in loop to iterate through the object 
for(key in myObject){ 
    console.log("this is the key: ", key, ", and this is the value: ", myObject[key]); 
};