2016-10-24 17 views
0

私は別のコレクションに格納されているaccountActiveDateに基づいてユーザーのリストを返そうとしています。私がconsole.log candidateUserIDByDateを指定した場合、ユーザーは正しい順序で返されますが、ソートされていないvar candidateUserIDByDateを使用してMeteor.users.findを返します。別のコレクションの日付を使用してユーザーを並べ替え

パス:

テンプレートヘルパー:sort.js

let sortCandidatesByDate = CandidateAccountStatus.find({}, {sort: {accountActiveDate: 1}}).fetch(); 
let candidateUserIDByDate = _.map(sortCandidatesByDate, function(obj) { 
    return obj.candidateUserId; 
}); 

return Meteor.users.find({$and: [{_id: { $ne: Meteor.userId() }}, {_id: { $in: candidateUserIDByDate }}]}); 

答えて

1

私はこのような正しいユーザーを返すために、別のヘルパーを使用して、CandidateAccountStatusとループ内を返す、(おそらくハック)溶液になると思います:

status: function(){ 
    //you might want to do {$ne: {Meteor.userId()}} for the correct field 
    //in your selector if you don't want currentUser status 
    return CandidateAccountStatus.find({}, {sort: {accountActiveDate: 1}}) 
}, 

statusUser: function(){ 
    //change correctField to how you save the userId to 
    //your CandidateAccountStatus schema 
    return Meteor.users.findOne({_id: this.correctField}) 
} 

HTML

{{#each status}} 
    {{#with statusUser}} 
     <!-- You have the user object here --> 
     {{_id}} <!-- gives the userId --> 
    {{/with}} 
{{/each}} 
関連する問題