0

I am working on a sample app that will act as a journal. As such, I need to create dynamic routes.

My code in router.js looks like:

Router.route(':month/:day/:year', {
name: 'listView',
data: function () {
    var month = this.params.month;
    var day = this.params.day;
    var year = this.params.year;
    return Links.findOne({day: day, month: month, year: year}); 
}

My listView template is simple:

<template name="listView">
<li>{{title}} - {{url}} - {{comments}}</li></template>

Whenever I console.log any of the variables (day, month, year) I get back the expected values, but when they are put in the Links.findOne method, they don't seem to work (i.e. my data context does not get rendered in my template. If I hardcode the day, month and year in, the data context is properly passed to my template and it works.

Can someone help explain why variables will not work when hardcoded values do?

gsd20
  • 1
  • Do you have any helper? – yoK0 Nov 16 '14 at 21:56
  • @yoK0 no I do not since the data context is being set at the router level. Do I need one? – gsd20 Nov 17 '14 at 13:41
  • I was wondering how else meteor will know what to render in place of 'title' 'url' and 'comments' – yoK0 Nov 18 '14 at 06:09
  • @yoK0 isn't the idea that the data context passes the data to the template without the need for the helper function? – gsd20 Nov 22 '14 at 15:19
  • I figured this out. In my database I am storing day, month and year as integers. this.params.day/month/year all equate to a string. Using the parseInt() method allowed me to solve for this. – gsd20 Nov 22 '14 at 16:21

0 Answers0