I am trying to implement a router with BackboneJS in my MeteorJS application. When you call the url "localhost: 3000/1", my router stores the identifier "1" in the session. After that, I want to take the identifier from the session and use it in my request to select an object from my collection. But whenever I try to use the session attribute in my request, it fails. So I want to know if there is a better way for routing with MeteorJS and why my request is not working.
test.js
Meteor.subscribe("test"); Test = new Meteor.Collection("test"); Session.set("id", null); Template.hello.test = function () { var avg = 0, total = 0, cursor = Test.find(), count = cursor.count(); cursor.forEach(function(e) { total += e.number; }); avg = total / count; var session_id = Session.get("id"); var test = Test.findOne({id: session_id});
test.html
<head> <title>test</title> </head> <body> {{> hello}} </body> <template name="hello"> <h1>Hello World!</h1> {{#if test}} {{#with test}} ID: {{id}} Name: {{name}} AVG: {{avg}} {{/with}} {{/if}} </template>
model.js
Test = new Meteor.Collection("test"); Test.remove({}); if (Test.find().count() < 1) { Test.insert({id: 1, name: "test1", number: 13}); Test.insert({id: 2, name: "test2", number: 75}); } Meteor.publish('test', function () { return Test.find(); });
fraherm Jul 12 2018-12-12T00: 00Z
source share