meteor - dynamic search with operator like in mongodb -


i newbie meteor , mongodb.. want ask how search data dynamically in mongodb.. here example

  template.maintemplate.itemsfounded = function() {     return item.find({itemname:{$regex: session.get('searchitemname')}});   };  template.templatesearchitem.events({     'click .searchitem' : function() {       var $itemname =  $('#textboxsearchitemname');       session.set('searchitemname', '/'+ $itemname.val()+ '/');     }   }); 

when runs, display nothing.. can me? sorry silly question..

thanks

the problem come fact not building regex simple string this:

session.set('searchitemname', '/'+ $itemname.val()+ '/'); 

in order build regex should create new regexp object use in mongo $regexquery. should rewrite "itemsfounded" not proper way declare helpers in meteor:

template.templatesearchitem.events({   'click .searchitem' : function() {     var $itemname =  $('#textboxsearchitemname');     session.set('searchitemname', $itemname.val());   } }); ... template.maintemplate.helpers({   itemsfounded: function() {     var regex = new regexp(session.get('searchitemname'), 'i'); //'i' case insensitive search     return item.find({itemname:{$regex: regex}});   }       }); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -