收到错误:无法在“节点”上执行“appendChild”

Getting the error: Failed to execute 'appendChild' on 'Node'

本文关键字:节点 执行 appendChild 错误      更新时间:2023-09-26

我使用纯javascript原型函数创建一个复选框列表,并在我们迭代数据时附加它们。一切都是使用javascript和css创建的。当我运行它以便它可以绘制复选框列表时,它会给我一个错误:

"Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'."

对于此行:

results.push(this.list.appendChild(letter.draw));

我确定复选框输入原型没有任何问题,因为它在其他任何地方都可以正常工作。我在 FormTicket 中做错了什么。谁能帮我做错了什么?表单页面是表单票证

FormTicket.prototype.respond = function(data) {
  var letter, i, len;
  this.letters = [];
  for (i = 0, len = data.length; i < len; i++) {
    letter = data[i];
    this.letters.push(new ParaInfo({
      InfoIndividual: letter
    }));
  }
  return this.drawList();
};
FormTicket.prototype.drawList = function() {
  var letter, i, len, ref, results;
  ref = this.letters;
  results = [];
  for (i = 0, len = ref.length; i < len; i++) {
    letter = ref[i];
    results.push(this.list.appendChild(letter.draw));
  }
  return results;
};

ParaInfo 方法中的绘制函数为:

 ParaInfo.prototype.draw = function() {
  this.e = new CheckBoxInput({
    title: this.InfoIndividual,
    float: 'left',
  });
  return this.e;
};

仅供参考,复选框输入是另一个原型,其中一部分如下:

CheckBoxInput.prototype.build = function(arg) {
  this.title = arg.title;
  this.float = arg.float;
};
CheckBoxInput.prototype.draw = function() {
  var box, check;
  this.item = document.createElement('div').addClass('checkboxInput');
  return this.item;
};

解决了。 需要调用 ".draw().draw()"即最初只调用 ParaInfo的 .draw()。添加了另一个".draw()",它调用CheckBoxInput的draw。正确调用追加:

  results.push(this.list.appendChild(letter.draw().draw()));

也感谢用户插件的宝贵意见。