2016-06-13 5 views
1

からの眺めに私は、流星のユーザーアカウントの文書を次ていますリスト配列オブジェクトの値流星のユーザーコレクション

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

私はこのようになります。私の見解でfriendlist配列からのuserIdを反復処理したい:

Friends List: bbbb, cccc, dddd 

HTMLは、私は次のように仮定になります

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

とfollowinのようなtemplate.helper g:

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

私はこれを行うことはできません。どんな助け?

答えて

1

あなたのヘルパーからの配列を返した後、それを反復処理する必要があります。

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

JS:また

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

モデリングPOVから、あなただけのfriendlistuserIdを持っている場合配列の代わりにオブジェクトの配列の代わりに文字列の配列を持つことができます。あなたの明確化のため

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

感謝。私はその文書をモデル化するあなたの提案に従った。注意するには、配列を使用するときは、{{this}}を使用して配列項目をビューに表示します。 – Edward

+0

はい、テンプレートを変更する必要があります。 –

関連する問題