I have a Meteor Collection called Posts as shown below:
Posts = new Meteor.Collection('posts');
I want to categorize them by a field I call "genre" and have different genre posts appear in different tabs in my navigation bar. I've tried installing tags for meteor and creating multiple Collections, but those attempts have not been successful.
Does anyone know how I can categorize one Posts collection (if possible) into multiple feeds on different tabs and sort them by time created?
Actually this is pretty easy with meteor
You should first create and event handler like this if you don't know about event handlers or insert into collections take a look into insert method on Mongo.Collections and event handlers Meteor Events Handlers
This is how a Event handler look on MeteorJs
template.navbar.events({
'click #button':function(){
Posts.insert({genre:"Rock"})
}
})
or if you want to skip the event handler (just for testing purposes) create a folder named /Server
with a file inside name testInsert.js
with this code
so our path look like this /appName/server/testInsert.js
if (Posts.find().count() === 0) {
Posts.insert({
genre: 'Rock',
});
Posts.insert({
title: 'Music',
});
Posts.insert({
title: 'Art',
});
}
Now we need to show the Posts Data on the Meteor template, so we need a Meteor Template.helpers
Template.navbars.helpers({
showGenre:function(){
return Posts.find();
}
})
And this is how we call that helper on the Template,Meteor uses the spacebars engine on the templates.
If you wanna take a deep look into Spacebars
take a look into this Understanding Spacebars
<template name="navbars">
{{#each showGenre}}
<!-- navbar stuff go here -->
{{genre}} <!-- here you are only calling genre field from Posts Collection -->
{{/each}}
</template>
GO Further
run this commands to get some meteor apps examples.
meteor create --example todos or
meteor create --example localmarket
OR take a look into this resources if you want to learn meteor more properly