mhlavacka
mhlavacka

Reputation: 701

How to combine two collections objects to one table while looping over all objects in Meteor.js?

I'm working on the simple Meteor Chat application. I have two different collections, textMessages and FS.images. I need to display those element based on time in one flow. Now I submit them both apart from each other and can't figure the way, while looping over them using #each handler. Template code :

<ul class="list-group">
    {{#each messages}}
    <li class="list-group-item">
        <span class="badge">x</span>
        UserN: {{text}}
    </li>
    {{/each}}  
</ul>

<ul class="list-group">
    {{#each showImages}}
      {{#unless this.isUploaded}}
        {{> FS.UploadProgressBar bootstrap=true}}
      {{/unless}}
        {{> imageItem}}
    {{/each}}
</ul>

Upvotes: 3

Views: 447

Answers (1)

Oddadmix
Oddadmix

Reputation: 180

You can create a helper in the template that would combine both collections results and sort them by date if each user has set of images and text.

If each message has a set of images you can use this package for creating helper for the collection in such a way you can get the set of images for a certain message.

meteor-collection-helpers

Upvotes: 1

Related Questions