[英]Grails Calendar plugin throws stack / recursion error
日歷插件版本:CURRENT RELEASE 1.2.1
我遵循了grails插件文檔中提到的步驟,在所有類型的瀏覽器中都收到以下錯誤
Chrome 14.0835:未捕獲RangeError:超出了最大Callstack大小。
Firefox 6.02:太多的遞歸calendar.js行1851
IE 9:堆棧空間不足calendar.js行1850
令人討厭的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);
};
重新定義Date.setFullYear()
。 在此“舊的jscalendar”頁面上查看注釋#124和#125。
評論#124(克里斯·利弗利(Chris Lively))
建議更新calendar.js(在底部,第1850行附近)。
對於那些獲得遞歸錯誤的人。 您只需要注釋幾行。 見下文。
//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); };
評論#125(larisa的回復)
由於頁面上包含多個日歷JavaScript,因此出現了遞歸問題。 結果,Date補丁兩次重新定義setFullYear函數,並在執行時導致無限循環。 我們通過確保僅將函數重新定義一次來解決此問題:
if(Date.prototype.msh_oldSetFullYear == null) { Date.prototype.msh_oldSetFullYear = Date.prototype.setFullYear; }
這兩個建議都建議對calendar.js進行更新,由於它是隨插件一起提供的,因此並不理想。
兩個建議:
<calendar:resources/>
? 如果是這樣,請刪除其中之一。 這對我有用:
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);
};
我面臨着同樣的問題,我已經將<calendar:resources/>
放置在我的主jsp以及在jsp中呈現的模板中。 刪除其中一個解決了該問題。
我解決此問題的方法是
1)下載了插件的源代碼2)在本地創建了一個同名插件。 3)將原始源文件復制到我創建的本地插件中4)按照上述建議更改javascript文件5)編譯並打包插件6)在我的主項目中刪除了舊插件7)從zip文件中安裝了新創建的插件從第5步創建。
它像魅力一樣運作。
感謝Rob Hruska指出我在javascript文件中的注釋位置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.