javascript - Passing an _id and a search query in the string -


using meteor test project. can't figure out how pass id , search parameter when playing sample todo app have.

for moment, have in iron router:

this.route('team', {      path: '/team/:_id',      onbeforeaction: function() {          this.todoshandle = meteor.subscribe('todos', this.params._id);          // filter mongodb search text  }}); 

the thing is, want pass optional search parameter search todos. path: '/team/:_id(/search/:search)?'

any ideas how this?

from explanation, sounds like control documents published client, rather publishing of them , narrowing down result set on client. in case, suggest first defining publication on server so:

meteor.publish('todosbyteamidandsearch', function(todoteamid, searchparameter) {     var todoscursor = null;      // check teamid , searchparameter existence , set     // todoscursor accordingly. if neither exist, return empty     // cursor, while returning subset of documents depending on     // parameter existence.     todoscursor = todos.find({teamid: todoteamid, ...}); // pass parameters accordingly      return todoscursor; }); 

to read more defining more granular publications, check this out.

with publication 1 above defined, can setup route so:

router.route('/team/:_id/search/:search', {     name: 'team',     waiton: function() {         return meteor.subscribe('todosbyteamidandsearch', this.params._id, this.params.search);     },     data: function() {         if(this.ready()) {             // access todos collection             var todos = todos.find({});         }     } }); 

as can see example route definition, can define path route see directly in call router.route() function , access parameters directly passed in in waiton route option. since publication has been defined suggested, can pass route parameters right meteor.subscribe() function. then, in data route option, once have checked subscription ready, can access todos collection normal no further narrowing of result set if not need so.

in order learn more how configure routes, check these 2 links out: iron router route parameters , iron router route options


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -