There is a custom user field that is filled by the user upon clicking a button with an ID of an item from another collection. However, when returned, all saved items are displayed in one HTML tag instead of each saved item having its own tag. The result ends up looking like this
https://i.sstatic.net/zRHwD.png
For example:
<p>CategoryPublication-98,CategoryPublication-2,CategoryPublication-57</p>
Instead of how it should be:
<p>CategoryPublication-98</p>
<p>CategoryPublication-2</p>
<p>CategoryPublication-57</p>
This is the publish function:
Meteor.publish(null, function() {
return Meteor.users.find({_id:{$in:fields.name}}).fetch();
});
The HTML template:
<template name="userTimeline">
{{#if currentUser}}
<div class="timeline-user">
{{#each name}}
<p>{{name}}</p>
{{/each}}
</div>
{{/if}}
</template>
The helper function:
Template.userTimeline.helpers({
name: function() {
return Meteor.user().name;
}
});
The insert function:
Template.CategoriesMain.events({
'click .toggle-category': function(e){
var ob = this._id;
var id = $.makeArray( ob );
console.log(id);
e.preventDefault();
Meteor.call('addingCategory', id, function(error, user){ console.log(id)});
},
});
The methods used:
Meteor.methods({
addingCategory: function(name) {
console.log(Meteor.userId());
Meteor.users.update({
_id: Meteor.userId()
},
{
$addToSet: {
name: name
}
});
}
});