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 $regex
query. 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
Post a Comment