Reputation: 175
I have a problem accessing the data from an route.
Router.route('/view/:_id', {
name: 'locationView',
data: function() { return Locations.findOne(this.params._id); }
});
Locations
is a MongoDB Collection that i've subscribed to. I can access it via a helper method on another template without problems. It has objects like name, address etc.
<template name="locationView">
<h1>{{name}}</h1>
</template>
Application hosted on meteor.com
On the front-page you can see that the entries from Locations are accessible from other templates over helper methods. So why i can't access them via the data object from the route?
The problem was adding the objects via mongo shell. That caused the ObjectID(xxx) stuff to appear in the _id of the object.
I've added some test objects via collection method 'insert' and everything works fine!
Upvotes: 0
Views: 53
Reputation: 175
The problem was adding the objects via mongo shell. That caused the ObjectID(xxx) stuff to appear in the _id of the object.
I've added some test objects via collection method 'insert' and everything works fine!
Upvotes: 0
Reputation: 4820
The data
defined in your route is stored in your template instance, ergo Template.instance().data
. You can also access it in onRendered
using simply this.data
:
Template.locationView.onRendered(function () {
var data = this.data;
});
Upvotes: 1
Reputation: 122
I just tried you application and i saw this url:
http://mhaehnel-compass.meteor.com/view/ObjectID(%22554e58c15eb2cd41fc085c0e%22)
The ObjectID() part is just for mongodb and is not supposed to be in you url.. that's why meteor is not doing the thing you expected. This could be an example how you would set your link to the locationView route
{{pathFor 'locationView' _id = this._id}}
Hope this helps
Upvotes: 1