So my question is, if it is possible to return more than 1 collection like:
Template.example.helpers({
return Collection1.find({}) && Collection2.find({});
})
to have access to all fields of both colletions in the data-context? Or is there an other way to accomplish this?
Believe you can return an array.
return [Stuff.find(), OtherStuff.find()]
argh, wont work properly
my goal is it to keep the collection2 “in mind” for later use eg. {{collection2.property}}
in my template but show collection1 normaly. i use reactive-table where i call a the collection with {{> reactiveTable collection=exampleCollection settings=tableSettings}}
where the collection=exampleCollection
is pointing to the helper-function:
Template.example.helpers({
exampleCollection: function () {
return Collection1.find({}) && Collection2.find({});
}
})
Template.example.helpers({
data: {
collection1: function () {
return Collection1.find({});
},
collection2: function () {
return Collection2.find({});
}
},
unionData: function () {
return _.concat(Collection1.find().fetch(), Collection2.find().fetch())
}
});
wont work for me - do you have any other packages installed?
it says:
Exception in template helper: TypeError: _.concat is not a function
I think this is heading towards joining collections?
i use lodash replace meteor’s underscore
you can use js native concat too
you might want to use first one
Template.example.helpers({
data: {
collection1: function () {
return Collection1.find({});
},
collection2: function () {
return Collection2.find({});
}
}
});
<template name="example">
{{#each data.collection1}}
<p>{{something}}</p>
{{#each data.collection2}}
{{something}}
{{/each}}
{{/each}}
<hr>
{{#each data.collection2}}
<p>{{something}}</p>
{{#each data.collection1}}
{{something}}
{{/each}}
{{/each}}
</template>
this package is awesome try this one
meteor add manuel:viewmodel
docs
Template.example.viewmodel({
collection1: Collection1.find(),
collection2: Collection2.find()
});
<template name="example">
{{#each data.collection1}}
<p>{{something}}</p>
{{#each data.collection2}}
{{something}}
{{/each}}
{{/each}}
<hr>
{{#each data.collection2}}
<p>{{something}}</p>
{{#each data.collection1}}
{{something}}
{{/each}}
{{/each}}
</template>
that merge every Template method into one viewmodel
thanks for your help
I will definitly keep that in mind and ViewModel looks very interesing!
But I solved my problem with a inception-like-strategy
I put another reactive table inside my reactive table but this time with a pointer to the collection2. its a mediocre solution but it works for me. mabye I will use ViewModel for refactoring
thanks everyone for the help