0
我一直在這一段時間。問題在於這行代碼從未得到執行let userSchool = SchoolDb.findOne({slug: Session.get('ReceivedSlug')});
當我登錄控制檯時,我發現slug是動態的,因爲它假設從db中獲取記錄。我該怎麼辦? 的oncreated模板FindOne從未得到執行流星js
Template.view.onCreated(function() {
Session.set('ReceivedSlug', FlowRouter.getParam('myslug'));
this.autorun(function() {
Meteor.subscribe('SingleSchool', Session.get('ReceivedSlug'));
});
});
助手功能
singleSchool: function() {
if (Meteor.userId()) {
console.log('reactive this ---- ' +Session.get('ReceivedSlug'));
let userSchool = SchoolDb.findOne({slug: Session.get('ReceivedSlug')});
if (!userSchool) {
Bert.alert('School not present', 'danger', 'growl-top-right');
} else {
console.log('school name ----' +userSchool.slug);
return userSchool;
}
}
},