gpt4 book ai didi

javascript - 列出 Meteor 用户 Collection View 中的数组对象值

转载 作者:行者123 更新时间:2023-11-27 22:53:49 25 4
gpt4 key购买 nike

我有以下 Meteor 用户帐户文档:

{
"_id":"aaaa",
"profile":{
"friendlist":[
{"userId":"bbbb"},
{"userId":"cccc"},
{"userId":"dddd"}
]
}
}

我想从我的 View 上的好友列表数组中迭代 userId,如下所示:

Friends List: bbbb, cccc, dddd

我认为 html 看起来像下面这样:

<template name="friendListCard">
Friends List:
{{#each searchFriendList}}
{{profile.friendlist.userId}},
{{/each}}
</template>

和 template.helper 如下所示:

Template.friendListCard.helpers({
searchFriendList: function(){
Meteor.users.find({_id:Meteor.userId()})
},
});

我似乎无法实现这一点。有什么帮助吗?

最佳答案

您需要从助手返回数组,然后迭代它:

<template name="friendListCard">
Friends List:
{{#each searchFriendList}}
{{userId}},
{{/each}}
</template>

js:

Template.friendListCard.helpers({
searchFriendList: function(){
return Meteor.users.findOne(Meteor.userId()).profile.friendlist;
},
});

同样从建模 Angular 来看,如果您的 friendlist 数组中只有 userId,那么您可以只拥有一个字符串数组,而不是一个对象数组。

friendlist: ["bbbb","cccc","dddd"]

关于javascript - 列出 Meteor 用户 Collection View 中的数组对象值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37798209/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com