Accessing template level subscription inside event handler - syntax?

I am having trouble accessing a subscription inside an event handler:

on the SERVER, I am publishing:

Meteor.publish('basicInfoPub',function() {
    if (!this.userId) {
        return this.ready();
    return BasicInfo.find(
        {  userId:this.userId },
        { fields: {firstName:1, lastName:1, middleName:1, someCodes:1}


On the CLIENT, am subscribing, and then trying to access the subscription data in an event handler.


    basicInfoSub = this.subscribe('basicInfoPub');

//event handler
    'click #populateFormButton': function(e,instance){

In the event handler, none of the 3 options shown actually work (, instance.basicInfoSub, or How do I access firstName, lastName etc inside the event handler?


You donā€™t need to access the template instance. The data that is returned by the subscription goes into the (globally accessible) client-side cache, minimongo. All you need to do to get the data on the client is:

'click #populateFormButton': function(e, instance){
  var basicInfo = BasicInfo.findOne({_id: Meteor.userId()});

This is assuming the data has been returned from the subscription by the time the user clicks the button (pretty safe bet).

Also note the instance.$ rather than $, so the scope in which jquery searches is limited to html in that particular template instance.

(The BasicInfo collection should be instantiated on both client and server.)

1 Like

Thanks for the clear explanation!