2016-07-24 66 views
0

我有一个自定义用户字段,用户通过单击具有另外一个集合,但是当我回到了它,我得到一个HTML标签的物品的一个列表,而不是在自己的标签返回每个保存的项目,结果看起来像这样Meteor.user自定义字段在一个html标签中显示项目的单个列表,而不是在其自己的标签中的每个项目

enter image description here

即它像这

<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 
     } 
    }); 
    } 
}); 

回答

0

如果您有:

{{#each name}} 
    <p>{{name}}</p> 
{{/each}} 

有关于name在内<p></p>值不确定性。由于您只是返回一个字符串数组而不是对象,因此数组中没有name键。

而是做:

{{#each name}} 
    <p>{{this}}</p> 
{{/each}} 
相关问题