2017-09-26 5 views
0

私はしばらくこの状態にいました。問題は、このコード行が決して実行されないことです。let userSchool = SchoolDb.findOne({slug: Session.get('ReceivedSlug')});コンソールにログオンすると、dbからレコードをプルすると仮定しているので、slugが動的であることがわかります。私は何をすべきか? oncreatedテンプレートFindOneは決して実行されないMeteor 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

は、サブスクリプションは、取得したデータを持っているかどうかをチェックしてくださいすることができます。また、内部のコンソールは、スラッグが変更されたときにデータが公開されるかどうかを公開します。サブスクリプションが

Meteor.subscribe('SingleSchool', Session.get('ReceivedSlug'), { 
    onReady: function(){ 
     console.log(SchoolDb.find({}).fetch()); 
    } 
}); 
を働いているかどうかを確認するためのコード以下

使用

関連する問題