2015-06-28 66 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]); 
};