简体   繁体   English

Grails Calendar插件抛出堆栈/递归错误

[英]Grails Calendar plugin throws stack / recursion error

Calendar plugin version :CURRENT RELEASE 1.2.1 日历插件版本:CURRENT RELEASE 1.2.1

I followed steps as mentioned in the grails plugin documentation, I get the following error in all types of browser 我遵循了grails插件文档中提到的步骤,在所有类型的浏览器中都收到以下错误

Chrome 14.0835: Uncaught RangeError: Maximum Callstack size exceeded. Chrome 14.0835:未捕获RangeError:超出了最大Callstack大小。

Firefox 6.02: Too much recursion calendar.js line 1851 Firefox 6.02:太多的递归calendar.js行1851

IE 9: Out of stack space calendar.js line 1850 IE 9:堆栈空间不足calendar.js行1850

The offending jscalendar code is this: 令人讨厌的jscalendar代码是这样的:

Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear;
Date.prototype.setFullYear = function(y) {
    var d = new Date(this);
    d.__msh_oldSetFullYear(y);
    if (d.getMonth() != this.getMonth())
        this.setDate(28);
    this.__msh_oldSetFullYear(y);
};

Which redefines Date.setFullYear() . 重新定义Date.setFullYear() Have a look at comments #124 and #125 on this "old jscalendar" page . 在此“旧的jscalendar”页面上查看注释#124和#125。

Comment #124 (by Chris Lively) 评论#124(克里斯·利弗利(Chris Lively))

Suggests updating calendar.js (near the bottom, ~line 1850). 建议更新calendar.js(在底部,第1850行附近)。

For those getting the recursion error. 对于那些获得递归错误的人。 You just need to comment a few lines. 您只需要注释几行。 See below. 见下文。

 //Date.prototype.msh_oldSetFullYear = Date.prototype.setFullYear; Date.prototype.setFullYear = function(y) { var d = new Date(this); //d.msh_oldSetFullYear(y); if (d.getMonth() != this.getMonth()) this.setDate(28); //this._msholdSetFullYear(y); }; 

Comment #125 (reply by larisa) 评论#125(larisa的回复)

The problem with recursion occurs due to multiple includes of calendar JavaScript on a page. 由于页面上包含多个日历JavaScript,因此出现了递归问题。 As a result Date patch redefines setFullYear function twice and causes infinite loop when it gets executed. 结果,Date补丁两次重新定义setFullYear函数,并在执行时导致无限循环。 We fixed it by making sure that function is redefined only once: 我们通过确保仅将函数重新定义一次来解决此问题:

 if(Date.prototype.msh_oldSetFullYear == null) { Date.prototype.msh_oldSetFullYear = Date.prototype.setFullYear; } 

Both of these suggest updates to calendar.js, which isn't ideal since it's delivered with the plugin. 这两个建议都建议对calendar.js进行更新,由于它是随插件一起提供的,因此并不理想。

Two suggestions: 两个建议:

  • Make sure you're not importing the calendar resources twice. 确保您没有两次导入日历资源。 Do you have a <calendar:resources/> in your main layout and your view GSP? 您的主布局视图GSP中是否有<calendar:resources/> If so, remove one of them. 如果是这样,请删除其中之一。
  • If that doesn't work, perhaps use a different plugin. 如果那不起作用,请使用其他插件。 The calendar plugin looks like it hasn't been updated in a while (it's using an older version of jscalendar). 日历插件看起来好像已经有一段时间没有更新了(它使用的是jscalendar的旧版本)。 If you're feeling ambitious, you could go update the plugin yourself! 如果您有雄心壮志,可以自己更新插件!

This works for me: 这对我有用:

if (Date.prototype.__msh_oldSetFullYear == null) {
    Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear;
}
Date.prototype.setFullYear = function(y) {
    var d = new Date(this);
    Date.prototype.__msh_oldSetFullYear.apply(d, arguments);
    if (d.getMonth() != this.getMonth())
        this.setDate(28);
    Date.prototype.__msh_oldSetFullYear.apply(this, arguments);
};

I was facing same issue, I had placed <calendar:resources/> in my main jsp as well as in the template which was rendered in the jsp. 我面临着同样的问题,我已经将<calendar:resources/>放置在我的主jsp以及在jsp中呈现的模板中。 Removing one of them solved the issue. 删除其中一个解决了该问题。

The way I resolved this issue is 我解决此问题的方法是

1) Downloaded the source of the plugin 2) Created a plugin with the same name locally. 1)下载了插件的源代码2)在本地创建了一个同名插件。 3) Copied the original source files to the local plugin I created 4) Changed the javascript file as suggested above 5) Compile and package the plugin 6) Removed the old plugin in my main project 7) Installed the newly created plugin from the zip file created from step 5. 3)将原始源文件复制到我创建的本地插件中4)按照上述建议更改javascript文件5)编译并打包插件6)在我的主项目中删除了旧插件7)从zip文件中安装了新创建的插件从第5步创建。

It worked like a charm. 它像魅力一样运作。

Thanks Rob Hruska for pointing me where to comment in the javascript file 感谢Rob Hruska指出我在javascript文件中的注释位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM