user3848987
user3848987

Reputation: 1657

Meteor: Build one new object with strings out of four results

I have filtered results from four different publications (with different structure).

Router.route('/anything/:_id', {
    name: 'anything',
    data: function () {
        return { 
            result1: Collection1.find({'article.reference': this.params._id}),
            result2: Collection2.find({'edition.section.reference': this.params._id}),
            result3: Collection3.find({'reference': this.params._id}),
            result4: Collection4.find({'anything.reference': this.params._id})
        };
    }
});

Right now I just display them like this:

<h4>Result 1</h4>
    {{#each result1}}
        {{#each article}}
            {{author}}. {{title}}. {{../journal}} ({{year}}):{{edition}}; S.{{pageNumbers}}
        {{/each}}
    {{/each}}

[...]

<h4>Result 4</h4>
    {{#each result4}}
        {{#each edition}}
            {{#each section}}
                {{../../author}}. {{../../book}} ({{../year}}). {{../edition}}. {{../../publisher}}. S.{{pageNumbers}}
            {{/each}}
        {{/each}}
    {{/each}}

I do this for every single result given in the router-data. So I get four sorted lists.

But I need just one big list with all elements in it sorted in general. Therefore I would like to build the string first (right now this is be done in the template) for every result (each Collection will be treated different as the result-string differs) and then sort the resulted array to push this in the template.

So the template would just be:

<h4>Result</h4>
    {{#each result}}
        <p>{{line}}</p>
    {{/each}}

Upvotes: 1

Views: 22

Answers (1)

user3142695
user3142695

Reputation: 17332

Wouldn't this be a choice?

var cursor = Collection.find();
cursor.forEach(function(doc){
  console.log(doc._id);
  // fill new object here...
});

Upvotes: 1

Related Questions