[英]Meteor.user custom field displaying a single list of items in one html tag instead of each item in its own tag
我有一個自定義用戶字段,該用戶字段由用戶單擊帶有另一個集合中某個項目的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
}
});
}
});
您在哪里:
{{#each name}}
<p>{{name}}</p>
{{/each}}
內部<p></p>
的name
值含糊不清。 由於您只是返回一個字符串數組而不是對象,因此該數組中沒有name
鍵。
而是:
{{#each name}}
<p>{{this}}</p>
{{/each}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.