You were right, the code was ok.
Is it possible that the problem comes from the fact i create the array using a call to the database. var arr = db.find({}).fetch()
And the events function take the object while it’s still empty… ?
Yes that probably is your issue. You need to call Template.instance_name.events(o); everytime your collection changes. In your case it would look something like this:
Template.insance_name.onCreated(function(){
this.autorun(function(){
var arr = db.find({}).fetch();
var o = {};
arr.map((name)=>{
o['click .'+name] = function (e, i) {
alert(name);
}
});
Template.instance_name.events(o);
});
});
Isnt it strange that db.find take so much time?
I tried using an async method to await db.fnd({}).fetch() but it doesnt change the behavior.
Is there a way to avoid this problem?
Now the events are loaded, but somehow only once very two times…