Created
March 9, 2015 16:32
-
-
Save misutowolf/b891b518499f6ecfebda to your computer and use it in GitHub Desktop.
groupSingle
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
| Template.groupsSingle.helpers({ | |
| // Generate tag list | |
| tagList: function() { | |
| return this.tags; | |
| }, | |
| rosterList: function() { | |
| var theHTML = ""; | |
| // Grab parts of document | |
| var theRanks = this.ranks; | |
| var theRoster = this.roster; | |
| var numRanks = this.ranks.length; | |
| var template = _.template("<li><%= user %></li>"); | |
| // Iterate over groups, using Underscore. | |
| for (var i = 1; i <= numRanks; i++) { | |
| var rankName = theRanks[i-1].name + "s"; | |
| theHTML += "<h5>" + rankName + "</h5>"; | |
| var theGroup = _.filter(theRoster, function(item) { return item.rank === i; }); | |
| console.log(JSON.stringify(theGroup)); | |
| // Check for empty rank (no members of rank) | |
| if (_.isEmpty(theGroup)) { | |
| theHTML += "<ul><li>None</li></ul>"; | |
| } else { | |
| theHTML += "<ul>"; | |
| _.each(theGroup, function(item) { | |
| theHTML += template({user: Meteor.users.findOne(item.user).profile.name}); | |
| }); | |
| theHTML += "</ul>"; | |
| } | |
| } | |
| return theHTML; | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment