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

前端 未结 2 633
清歌不尽
清歌不尽 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;
    };
    
    0 讨论(0)
  • 2021-01-12 06:22

    This error occurs when you pass large object as an argument to your method. For me for example the first Time I encountered this error, was when I passed a Meteor.Collection as an argument :s . I worked around that by passing the collection name as a String and then using eval() in the Methods to get the Collection on which proceed.

    Conclusion: Always use strings, integers, small arrays or really small objects as arguments for methods called from your event handlers.

    0 讨论(0)
提交回复
热议问题