0

I'm fairly new to meteor and have encountered a problem while trying to use Iron Router to pass a url parameter to a Collection and retrieve some data for display.

Specifically, I have a Collection with events and I'd like to have a page that display a single one in more detail.

PS: I've used Iron Router and Meteor's publish/subscribe logic succesfully for other tasks, such as displaying all events, creating them and saving them to a personal list.


event.html

<template name="event">
  <div class="page-header">
    <h1>{{title}}</h1>
  </div>
  <div class="container">
    <p>{{content}}</p>
  </div>
</template>

router.js

this.route('event',{
    path: '/event/:_id',
    waitOn: function () {
        return Meteor.subscribe('Events');
    },
    data: function () {
        return Events.findOne(this.params._id);
    }
});

Publishing happens on the server in publish.js and subscribing in the router
publish.js

Meteor.publish('Events', function () {
    return Events.find();
});

router.js

Router.configure({

    (..)

    waitOn: function() {
        return [
          Meteor.subscribe('Events'),
          Meteor.subscribe('myEvents')
        ];
    }
});

I've been looking at this tutorial by Manuel Schoebel link

All is fine up until the point where the Collection lookup is happening. When I log the result data from the Collection, it's undefined

data: function () {
    var event = Events.findOne(this.params._id);
    console.log(event);
    return event;
}
Michiel
  • 709
  • 9
  • 15
  • try changing this ```var event = Events.findOne(this.params._id);``` to ```var event = Events.findOne({_id: eventId}); //where var eventId = this.params._id``` and return ```{event: event}``` – Marius Darila May 13 '15 at 13:01
  • What does `console.log(this.params._id)` give you? – SylvainB May 13 '15 at 13:04
  • How about Events.findOne({_id: ObjectId(this.params._id)}); – mwarren May 13 '15 at 13:05
  • Silly enough, I placed a `:` some place it should not have been. Code is fully functional now :) Thank you all for your help! – Michiel May 13 '15 at 13:16

1 Answers1

0

Mistakenly, I placed a : where it should not have been.
Closing question.

Michiel
  • 709
  • 9
  • 15