gpt4 book ai didi

javascript - TypeError:this.element.down(...) 未定义 - Timeframe.js 和 Prototype

转载 作者:行者123 更新时间:2023-11-28 09:22:48 25 4
gpt4 key购买 nike

我当前正在使用名为 Timeframe.js 的 JS 脚本与 Prototype javascript 框架,创建日历小部件。在我的本地副本中,它工作得很好,但是在我的暂存环境中,我收到以下 javascript 错误:

TypeError: this.element.down(...) is undefined

this.element.down('div#' + this.element.id + '_container').insert(calendar);

该错误是指 timeframe.js 库文件中的第 97 行。它是以下方法的一部分:

// Scaffolding
createCalendar: function() {
var calendar = new Element('table', {
id: this.element.id + '_calendar_' + this.calendars.length, border: 0, cellspacing: 0, cellpadding: 5
});
calendar.insert(new Element('caption'));
var head = new Element('thead');
var row = new Element('tr');
this.weekdayNames.length.times(function(column) {
var weekday = this.weekdayNames[(column + this.weekOffset) % 7];
var cell = new Element('th', { scope: 'col', abbr: weekday }).update(weekday.substring(0,3));
row.insert(cell);
}.bind(this));
head.insert(row);
calendar.insert(head);
var body = new Element('tbody');
(6).times(function(rowNumber) {
var row = new Element('tr');
this.weekdayNames.length.times(function(column) {
var cell = new Element('td');
row.insert(cell);
});
body.insert(row);
}.bind(this));
calendar.insert(body);
this.element.down('div#' + this.element.id + '_container').insert(calendar);
this.calendars.push(calendar);
this.months = this.calendars.length;
return this;
},

我还验证了 this.element.id 的内容是有效的。该值最终是“div#calendars_container”,它是标记中存在的一个元素,因此 DOM 中不会丢失它。

我无法确定此问题的根源,我已确保拥有最新版本的 Prototype 和 Timeframe,但错误仍然发生。我已经以这种方式使用这些脚本有一段时间了,之前没有遇到过这种情况,有人能让我走上正确的道路吗?

最佳答案

我认为,您需要分享更多背景信息才能解决此问题。如果代码在本地运行良好,但在您的(可能是场外)暂存环境中运行良好,则可能是在执行到达相关行时并未加载所有代码。

我发现您的代码片段位于事件处理程序内;即使所有代码在到达此行之前已加载,也可能存在计时问题,Prototype 尚未使用 down() 函数扩展 this.element 对象?

很可能,您的登台环境之间的较大延迟会导致某些网络绑定(bind)函数接连执行,这与它在本地通常执行的方式相反。

在此行上放置一个断点,看看会发生什么。

关于javascript - TypeError:this.element.down(...) 未定义 - Timeframe.js 和 Prototype,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14778210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com