Meteor RangeError: Maximum call stack size exceeded. on keypress event

前端 未结 2 647
清歌不尽
清歌不尽 2021-01-12 05:55

Im trying to make a search box to filter down results of my returned collection in the client.

however when i actually try searching I\'m getting the above error in

2条回答
  •  春和景丽
    2021-01-12 06:04

    Changing this:

    Template.modules.events({
     'keypress input#search': function (event) {
      Session.set("currentFilter", $('input#search'));
     }
    });
    

    To This:

    Template.modules.events({
     'keyup input#search': function (event) {
      Session.set("currentFilter", $('input#search').val());
     }
    });
    

    I believe you just need the .val() on the jquery dom reference of the input field. Additionally I would recommend using keyup for the event for something like this.

    For getting the results out like you want you likely want to use a regular expression. Here's what I'm using in my app.

    Template.hudlies.found = function() {
      var searchVal = Session.get("searchFilter");
        if (searchVal != "") {
          var searchResults = Hudlies.find({ name: { $regex: '^.*' + searchVal + '.*', $options: 'i' } });
        };
    
      return searchResults;
    };
    

提交回复
热议问题