javascript - Retrieving a display results from a search -
i'm relatively new meteor.js , i'm trying search form work. far i'm not trying params work, come later.
i'm trying bunch of lifts display.
lib/router.js
router.configure({ layouttemplate: 'layout', loadingtemplate: 'loading', notfoundtemplate: 'notfound', waiton: function() { return meteor.subscribe('lifts'); } }); router.route('/', { name: 'liftslist' }); router.route('/lifts/search/:from-:to-:when', { name: 'liftssearch', waiton: function() { return meteor.subscribe('liftssearch'); } });
server/publications.js
meteor.publish('liftssearch', function() { var query = { fromloc: { $near : { $geometry: { type : "point" , coordinates: [ 6.11667, 45.9 ] } }, $maxdistance : 50 }}; return lifts.find(query); });
if try display results lifts.find(query).fetch(), returns actual results.
client/lifts_search.html
<template name="liftssearch"> <div class="container"> <h3>lifts search results {{hi}}</h3> <div class="lifts"> {{#each lifts}} hi {{> liftitem}} {{/each}} </div> </div> </template>
here got no lifts displaying, not little "hi" string.
thanks
unless there's code haven't included, {{#each lifts}}
isn't rendering because you're not defining lifts
anywhere. because you're populating lifts
collection, template doesn't automatically known lifts
refers (largely because totally arbitrary - exact query refer to?).
so, need define lifts
in either router data
function:
router.route('/lifts/search/:from-:to-:when', { name: 'liftssearch', waiton: function() { return meteor.subscribe('liftssearch'); }, data: function() { return { lifts: lifts.find() // add query if want } } });
or in template helper:
template.liftssearch.helpers({ lifts: function() { return lifts.find(); // add query if want } });
Comments
Post a Comment