Reputation: 5244
I am making multiple dynamic tables in meteor App.
The headers are coming from a different collection and the values are coming from different one.
The values of the table are dependent on the Template ID
Template.PdDisplay.CurrentProducts = productDB.find({"TEMPLATE_NAME: ActiveTempName"});
I want to display the values in the following format.
<template name="PdDisplay">>
{{#each CurrentProducts}}
//How to fecth values here if the header is generated as given below
{{/each}}
</template>
<template name="HeaderDisplay">>
{{#each Headers}}
{{this.NAME}}//Basically I have to find the values of {{this.NAME}}, It is acting as key for the table.
{{/each}}
</template>
Upvotes: 2
Views: 154
Reputation: 4948
You're trying to shove waaaaay too much logic into the view layer.
Instead, in the onCreated
, make a local collection along with a Tracker.dependency()
to keep it reactive. Then join the headers & the content together in that new local collection. Wrap the entire function in an autorun
and make the last line collectionDep.changed()
. Now, for headers you create a helper like:
function() {
collectionDep.depend()
return Object.keys(localCollection.findOne());
}
And then do your #each
over that helper function.
Whenever either of the underlying collection cursors change, it'll recreate the local collection which will feed your template.
Upvotes: 1