meteor - how to find document in mongodb with its id passed in textbox? -


i learning mongodb meteor js dont have knowledge of both mongodb , meteor.

below js code:

import { template } 'meteor/templating'; import { dbs } '../lib/collections.js'; import './main.html';  template.body.helpers({   /*temp1:[   {text:'my data1'}'   {text:'my data1'}   ]*/    dbs(){     return dbs.find({'user_id':'p123'});   } }); 

basically want pass user id in textbox , based on it,i want display other details of user.in above code passing manually , working.anyone suggest me should here ?

you can attach template instance reactivevar update event. use inside helper, helper re-execute everytime value change:

template.mytemplate.oncreated(function() {   this.currenttextbox = new reactivevar(); });  template.mytemplate.events({   "keyup .js-my-textbox"(event, instance) {     // event executed when type in input class "js-my-textbox"     instance.currenttextbox.set(event.target.value);   }, });  template.mytemplate.helpers({   dbs() {     const instance = template.instance();      return dbs.find({'user_id': instance.currenttextbox.get() });   }, }); 

edit: example of html part:

<template name="mytemplate">   <input type="text" placeholder="search" class="js-my-textbox">   {{#each db in dbs}}     <-- want, example: -->     <p>{{db.myfield}}</p>   {{/each}} </template> 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -