简体   繁体   中英

meteor.js - set controller to access collection

Could someone tell me what I may be missing in order to have access to data within a collection from a given page? I can access the events collection but not the venue one - here is the code:

//Controller

UserController = AppController.extend({
  waitOn: function() {
    return this.subscribe('events');
    return this.subscribe('users');
    return this.subscribe('venues');
  },
  data: {
    venues: Venues.find({}),
    events: Events.find({}),
    users: Meteor.users.find()

  }
});

UserController.helpers({
    'myEvents': function() {
        var organizerId = Accounts.userId();
        return Events.find({organizerId: organizerId})
    },
    'myVenues': function() {
        return Venues.find({})
    }
});

The publish & permission files are identical for events and venues, the controller is routed to the correct page, and the venue collection is visible from pages with other controllers.

Thank you for your time!

The reason why you can't access the Venue collection is because you are not subscribing to it. The two statements after return this.subscribe('events'); in your waitOn function are dead code, since a return statement terminates a function. As a result, you need to return an array of subscriptions:

UserController = AppController.extend({
  waitOn: function() {
    return [Meteor.subscribe('events'), Meteor.subscribe('users'), Meteor.subscribe('venues')];
  },
  data: {
    venues: Venues.find({}),
    events: Events.find({}),
    users: Meteor.users.find()
  }
});

Please note: I noticed two missing semicolons in your helper functions. I strongly recommend to fix that, as this may cause undesired operation of your Meteor application, due to the minifying process on deployment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM