2017-09-26 63 views
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; 
      } 
     } 
    }, 

回答

0

可否請您檢查訂閱是否已經獲取的數據。同時在內部控制檯發佈當slug改變時是否發佈數據。

使用下面的代碼檢查,如果訂閱工作

Meteor.subscribe('SingleSchool', Session.get('ReceivedSlug'), { 
    onReady: function(){ 
     console.log(SchoolDb.find({}).fetch()); 
    } 
});