Is there a way to keep the helpers dynamic in order to obtain a cursor? The user should be able to change the collection - through a click event - that is used to retrieve a list. However, when I check my console.log
, I'm seeing an undefined
for window[type]
. What could be causing this issue?
While article.find()
seems to be functioning properly, window[type]
is not...
imports/api/example/index.js
export const article = new Mongo.Collection('articles');
export const images = new Mongo.Collection('images');
imports/api/example/client/example.js
import { article, images } from '../';
Template.example.helpers({
list() {
const type = Template.instance().section.get();
console.log(type, window[type]); // result: 'article', undefined
return window[type].find(); // <- hence, this part is NOT functioning as intended
}
});
Template.example.onCreated(function() {
this.section = new ReactiveVar('article');
});
Template.example.events({
'click .target': function(event, template) {
const $this = $(event.currentTarget),
type = $this.attr('data-type');
template.section.set(type);
}
});