Meteor Publish-Composite nesting issue -
problem: have number of groups each have members belong different groups. each member has title (role) in each group. i’m trying list groups , display each member in group , title. i’m using reywood:publish-composite, , working except can’t title of each member display. think problem in template.groupmembers.helpers file
title: function() { console.log(this.roleid); // shows in console each member return titles.findone({titleid: this.roleid}); // doesn’t work },
collections:
groups { "_id" : "xfszahbeps2dskcwm", "name" : "generic group", "logo" : "generic-logo-hi.png" } members { "_id" : "vydtiakkukzyqdfvs", "groupid" : "xfszahbeps2dskcwm", "memberid" : "hrx8gbtyb5x8iqq52", "roleid" : "1" } meteor.users { "_id" : "hrx8gbtyb5x8iqq52", "profile" : { "name" : "bob lorros" }, } titles { "_id" : "byskpsyytykr8nypm", "titleid" : 1, "title" : "staff (non-voting)" }
server/publications/publications.js
meteor.publishcomposite('groupmembers', { find: function() { return groups.find({}, { sort: {name: 1} }); }, children: [ { find: function() { return titles.find(); }, find: function(group) { return members.find({groupid: group._id}); }, children: [ { find: function(member) { return meteor.users.find({_id: member.memberid}); } }, ] }, ] });
client/templates/test/test.js
template.groupmembers.helpers({ groupmembers: function() { return groups.find({}, { sort: {name: 1} }); }, members: function() { return members.find({groupid: this._id}); }, title: function() { console.log(this.roleid); // shows in console each member return titles.findone({titleid: this.roleid}); // doesn’t work }, membername: function() { return meteor.users.findone(this.memberid); }, });
client/templates/test/test.html
<template name="groupmembers"> <h4>group - members</h4> {{#each groupmembers}} <b>{{name}}</b><br> {{#each members}} {{membername.profile.name}} - title = {{title.title}} <br> {{/each}} <br> {{/each}} </template>
output : this ouput
looking @ different perspective, think use alanning:roles accomplish you're looking for. can use role 'title' in case , 'group' replace groups. here's documentation:
Comments
Post a Comment