I have a custom user field that get populated by the user on click of a button with an id of an item from another collection, however when i return it, i get a single list of the items in one html tag, instead of returning each saved item in its own tag with the result looking like this
ie its like this
<p>CategoryPublication-98,CategoryPublication-2,CategoryPublication-57<p>
when it should be like this
<p>CategoryPublication-98</p>
<p>CategoryPublication-2</p>
<p>CategoryPublication-57</p>
this is my publish
Meteor.publish(null, function() {
return Meteor.users.find({_id:{$in:fields.name}}).fetch();
});
my html
<template name="userTimeline">
{{#if currentUser}}
<div class="timeline-user">
{{#each name}}
<p>{{name}}</p>
{{/each}}
</div>
{{/if}}
</template>
my helper
Template.userTimeline.helpers({
name: function() {
return Meteor.user().name;
}
});
my insert
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)});
},
});
My methods
Meteor.methods({
addingCategory: function(name) {
console.log(Meteor.userId());
Meteor.users.update({
_id: Meteor.userId()
},
{
$addToSet: {
name: name
}
});
}
});
Where you have:
{{#each name}}
<p>{{name}}</p>
{{/each}}
There's ambiguity about the value of name
in the inner <p></p>
. Since you're just returning an array of strings instead of objects there is no name
key in the array.
Instead do:
{{#each name}}
<p>{{this}}</p>
{{/each}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.