0
Meteorクライアントコードは、mongodbドキュメントがその関数にパラメータage
を提供しているので、サブスクリプションの準備ができたらopenNewTab(age);
関数を呼び出す必要があります。私は試したことの数を失ってしまった。誰がそれを行うことができますか? THXMeteorサブスクリプションが準備されているときに関数を呼び出す方法
//client/main.js
Meteor.startup(function() {
Tracker.autorun(function() {
Meteor.subscribe('myCol', Session.get('age'));
});
});
//client/lib.js
Template.footer.events({
'click #submit': (event) => {
event.preventDefault();
lib.usageEntry({taskSelected: taskSelected});
}
});
const lib = {
'usageEntry': function (Obj) {
// do stuff
lib[Obj.taskSelected](); // task1
},
'task1': function() {
let age = document.getElementsByClassName('age')[0].text()
Session.set('age', age); // so the reactive subscription works
openNewTab(age); //<=== how can this wait till subscription is ready?
}
}
//server
Meteor.publish('myCol', function (age) {
if (!this.userId || Meteor.users.findOne({_id:this.userId}).profile.notOk) return;
if (Meteor.users.findOne({_id:this.userId}).profile.hasOwnProperty('notPaid')) return;
let matcher = new RegExp('[0-9]{1,3}', "gi");
if (matcher.test(age)) {
return myCol.find({age: age}, {
fields: {
propName: true,
}, limit: 1
});
}
});