Skip to content

Instantly share code, notes, and snippets.

@misutowolf
Created March 9, 2015 16:32
Show Gist options
  • Select an option

  • Save misutowolf/b891b518499f6ecfebda to your computer and use it in GitHub Desktop.

Select an option

Save misutowolf/b891b518499f6ecfebda to your computer and use it in GitHub Desktop.
groupSingle
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