Reputation: 43
The question is: how to display complex documents returned from Mongodb.
Suppose I have two projects in my Projects collection and each project has 2 People embedded by their IDs from the People collection. Project.find() returns this CURSOR which I'm presenting as JSON for readability:
{ "_id" : "5ed5ade8-c140-46f7-8d9e-2344fc53df8e", "name" : "Project1", "personnel" : [ "b4690c4b-d126-4737-8f40-921234567890", "977a6335-a1be-4af5-8b3f-4abcdefghijk" ] }
{ "_id" : "23f073c7-a713-4713-86a7-7d6600433146", "name" : "Project2", "personnel" : [ "b4690c4b-d126-4737-8f40-92b43072d7a1", "977a6335-a1be-4af5-8b3f-48cd5f8328db" ]}
My template in .html file:
<template name="theProjects">
{{#each theTitles}}
Name: {{name}}
Personnel: {{personnel}}
{{/each}}
</template>
renders this in the browser:
Name: Project1
Personnel: b4690c4b-d126-4737-8f40-921234567890,977a6335-a1be-4af5-8b3f-4abcdefghijk
Name: Project2
Personnel:b4690c4b-d126-4737-8f40-92b43072d7a1,977a6335-a1be-4af5-8b3f-48cd5f8328db
Questions:
The {{personnel}} field is simply being filled in by the contents of the personnel array in the Projects collect. I want to list these separately on their own line. Can't figure that out. Just slicing won't do because...
The greater need clearly is to be able to manipulate and edit the Personnel data so the template has to be properly Meteor reactive.
Now the hard one: the personnel ID's from the People collection are embedded in the Project documents. How would I use Meteor to replace the ID's with the appropriate names from the Personnel collection and still keep their data reactivity?
I know this is a lot to ask but these kind of things seem like they are foundational to bigger and more complex web site.
Thanks everyone.
Upvotes: 0
Views: 679
Reputation: 873
https://gist.github.com/3220991
This is a gist I made to show you use the of Handlebars helpers. This will stay reactive and is very easy to use. I hope you can use it.
If you need more help or comments , just mention me.
Upvotes: 3