Created
July 31, 2012 21:54
-
-
Save lvbreda/3220991 to your computer and use it in GitHub Desktop.
Rendering MongoDB documents with Meteor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>Stackoverflow</title> | |
</head> | |
<body> | |
{{> hello}} | |
</body> | |
<template name="hello"> | |
<ul> | |
{{#each projects}} | |
<li> | |
<p>Name: {{name}}</p> | |
<p>Personnel: | |
{{#print personnel}} | |
<li>Name : {{name}}</li> | |
<li>Rank : {{rank}}</li> | |
{{/print}} | |
</p> | |
</li> | |
{{/each}} | |
</ul> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Projects = new Meteor.Collection("projects"); | |
Personel = new Meteor.Collection("personel"); | |
if (Meteor.is_client) { | |
/** Create a helper that will iterate over each id in the object **/ | |
Handlebars.registerHelper('print', function(context, options) { | |
var ret = "<ul>"; | |
for(var i=0, j=context.length; i<j; i++) { | |
var pers = Personel.findOne({_id:context[i]}); | |
if(pers){ | |
ret = ret + options.fn(pers);//Pass the retrieved personel object to the handlerbars function | |
} | |
} | |
ret += "</ul>" | |
return ret; | |
}); | |
Template.hello.projects = function(){ | |
return Projects.find({}); | |
} | |
/**Dummy**/ | |
var one = Personel.insert({name:"Lander",rank:"CEO"}); | |
var two = Personel.insert({name:"Sander",rank:"CEO"}); | |
var three = Personel.insert({name:"Tree",rank:"CEO"}); | |
Projects.insert({name:"Project 1",personnel:[one,two]}); | |
} | |
if (Meteor.is_server) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment