EDIT [SOLVED]: I had two entries in the database with the same pathname with one with no text -_-
Hi,
I am stuck with that problem. I am retrieving some data from the database when I jump to a certain route like so:
Router.route('/articles/:name', {
template: 'articles',
loadingTemplate: 'loading',
onBeforeAction: function () {
Session.set('edit', true);
this.next();
},
waitOn: function () {
return [Meteor.subscribe('articles', this.params.name), Meteor.subscribe('slides')];
},
data: function () {
return Articles.findOne({pathname: this.params.name});
},
action: function () {
if (this.ready()) {
return this.render();
}
}
});
Here my publishers:
Meteor.publish('articles', function (pathname) {
return Articles.find({pathname});
});
Meteor.publish('slides', function () {
return Slides.find({});
});
FindOne bind my articles
Template with the data retrieved from the db.
From this data I get the content of a list using an helper’s function.
Template.articles.helpers({
getParagraph: function () {
return this[Session.get('lang') || 'fr'] &&
this[Session.get('lang') || 'fr'].text);
}
});
The data:
{
en: {
text: ['some text', 'some other text']
},
fr: {
text: ['some text in fr', 'some other text in fr']
}
And I display it from my template with {{#each getParagraph}}
.
When I navigate through the links, the data renders in the view, but when I access the route directly entering the url manually the list is not filled with my texts yet.
So findOne returns an empty text array.
I think waitOn
wait until the subscriptions are ready, but since I could only manage to publish find() and not findOne(),
the view renders without waiting for the data.
I’ll be glad to know were I missed the point. Thanks!