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

标签 javascript prototypejs typeerror

我当前正在使用名为 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/

相关文章:

javascript - 当内容来自 Ajax 调用时访问 div 内容时出现问题

python - 类型错误:不支持的操作数类型/: 'str' 和 'str'

python - 类型错误:需要一个可读的缓冲区对象

javascript - 简单的主干应用程序加载集合然后动态迭代它时遇到问题

javascript - react 选择 - 在选定值上单击打开选择(多选)

javascript - 在 Internet Explorer 中使表单元素 onchange 气泡

node.js - bull-arena 要求将队列构造函数提供给 Arena

javascript - 在响应式 HTML 中向 PHP 表单添加验证

javascript - AngularJS 在重复 block 之外和脚本标记中使用 ng-repeat 值

javascript - 原型(prototype) Class.create() 的替代品;