【发布时间】:2016-07-24 09:38:11
【问题描述】:
我有一个自定义用户字段,用户在单击按钮时填充该字段,该按钮具有来自另一个集合的项目的 ID,但是当我返回它时,我会在一个 html 标记中获得一个项目列表,而不是将每个保存的项目返回到其自己的标签中,结果如下所示
就是这样
<p>CategoryPublication-98,CategoryPublication-2,CategoryPublication-57<p>
什么时候应该是这样的
<p>CategoryPublication-98</p>
<p>CategoryPublication-2</p>
<p>CategoryPublication-57</p>
这是我的发布
Meteor.publish(null, function() {
return Meteor.users.find({_id:{$in:fields.name}}).fetch();
});
我的html
<template name="userTimeline">
{{#if currentUser}}
<div class="timeline-user">
{{#each name}}
<p>{{name}}</p>
{{/each}}
</div>
{{/if}}
</template>
我的助手
Template.userTimeline.helpers({
name: function() {
return Meteor.user().name;
}
});
我的插入
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)});
},
});
我的方法
Meteor.methods({
addingCategory: function(name) {
console.log(Meteor.userId());
Meteor.users.update({
_id: Meteor.userId()
},
{
$addToSet: {
name: name
}
});
}
});
【问题讨论】:
标签: javascript arrays meteor