0
votes

If I do the following search:

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

I get the following:

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

My question, is how can iterate through the collection. I want to render one video at a time, so I can render the first video, and then on click, render the second, etc.

The thing is, I have many sets of videos, so this should be done dynamically. It should iterate through the next video.first, video.second.. etc.

Is that possible? I've looked into .next() but I think that works for an entire collection, not an object inside the collection.

Thank you in advance!

1
what have you tried? Can you show your template + helper code and what doesn't work, so that we have a starting point?Christian Fritz

1 Answers

1
votes

This is a JavaScript question, not necessarily Meteor. Use a for-in loop to iterate through objects.

// 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]);
};