【问题标题】:Meteor: Uncaught RangeError: Maximum call stack size exceeded流星:未捕获的 RangeError:超出最大调用堆栈大小
【发布时间】:2017-02-21 18:41:44
【问题描述】:

我对 Meteor 很陌生。我正在做简单的应用程序。 这是我遇到的问题:

Template.newFeedForm.events({
   'submit #new-feed-form'(event) {
       event.preventDefault();

       const target = event.target;
       const text = target.text;

       Meteor.call('feeds.insert', text);

       target.text.value = '';
   }
});

所以我有 newFeedForm 模板,在我的 feeds.js 中有

Meteor.methods({
    'feeds.insert'(text){
        check(text, String);
        //check(hashtag, String);

        // Make sure the user is logged in before inserting a task
        if (! this.userId) {
            throw new Meteor.Error('not-authorized');
        }
        console.log(this.userId);

        // Feeds.insert({
        //     text: text,
        //     owner: this.userId,
        //     username: Meteor.users.findOne(this.userId).username,
        //     createdAt: new Date()
        // });
    }
});

我在这里注释掉了 Feeds.insert,认为它会导致问题。好像有什么不一样的。 每当 Meteor.call 被执行时,我都会得到这个:

Uncaught RangeError: Maximum call stack size exceeded
    at Function._.(anonymous function) [as isArguments] (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:1068:30)
    at Object.EJSON.clone (http://localhost:3000/packages/ejson.js?hash=0f17ced99d522d48cd8f8b2139167fd06babd969:512:25)
    at http://localhost:3000/packages/ejson.js?hash=0f17ced99d522d48cd8f8b2139167fd06babd969:531:22
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:157:22)
    at Object.EJSON.clone (http://localhost:3000/packages/ejson.js?hash=0f17ced99d522d48cd8f8b2139167fd06babd969:530:5)
    at http://localhost:3000/packages/ejson.js?hash=0f17ced99d522d48cd8f8b2139167fd06babd969:531:22
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:157:22)
    at Object.EJSON.clone (http://localhost:3000/packages/ejson.js?hash=0f17ced99d522d48cd8f8b2139167fd06babd969:530:5)
    at http://localhost:3000/packages/ejson.js?hash=0f17ced99d522d48cd8f8b2139167fd06babd969:531:22
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:157:22)

不知道发生了什么。 这是我的 repo,它重现了这个错误: https://github.com/yerassyl/nurate-meteor

【问题讨论】:

  • 您是否导入错误?如给定的那样,您的代码不应该抛出该错误。您是否通过调试器运行过它?
  • 您确认您只输入了一次提交处理程序吗?

标签: meteor


【解决方案1】:

通常,当发生此类错误时(尤其是在处理 Meteor 方法时),这意味着您可能没有传递“正确”的数据(或您认为的数据)。

查看您的表单处理代码,我注意到您从未获得 textarea 文本数据。

const text = target.text;

target.text 返回实际的 textarea DOM 对象,但您真正追求的是对象包含的值。下面的代码将解决您的问题。

const text = target.text.value;

【讨论】:

  • 到底为什么我们会得到这个异常堆栈,但对于意外的数据?!我需要一个参考电子表格来区分我的流星错误
【解决方案2】:

当您使用 db.find() 与流星一起工作时。它给出了错误RangeError: Maximum call stack size exceeded,因为它返回的是响应式数据源的游标。

使用db.find().fetch() 获取数组形式的数据。

db.find() -> 返回游标,即响应式数据源

db.find().fetch() -> 从游标返回数组

【讨论】:

  • 谢谢!为我解决了一个巨大的服务器端问题。
猜你喜欢
  • 1970-01-01
  • 2018-01-24
  • 2014-08-01
  • 2015-10-28
  • 2013-05-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多