【问题标题】:Errors updating table contents with Prototype使用 Prototype 更新表格内容时出错
【发布时间】:2012-08-07 15:30:17
【问题描述】:

我想在 Prototype 中做这样的事情:

onSuccess: function(transport) {
    template = transport.responseText.evalJSON();
    form = event.up('form');
    form.select('.audio_channels').update(template.channelHtml);
}

表单标签是一个表格,我想替换它的内容。 channelHtml 是一串 HTML <tr> 标签。

我得到:

TypeError: 对象[object HTMLTableElement] 没有“更新”方法

所以我认为它不是扩展对象并尝试了Element.extend(form.select('audio_channels')),它返回一个空对象。然后我尝试form.select('.audio_channels').innerHTML(template.channelHtml),我得到TypeError: Object [object HTMLTableElement] has no method 'innerHTML'。然后我尝试使用 tbody 元素,我得到[object HTMLTableSectionElement] has no method 'innerHtml'

在我看来,这应该可行。 form.select('audio_channels') 正在返回正确的 DOM 元素。我需要怎么做才能根据我的 ajax 调用设置表格的内容?

【问题讨论】:

    标签: javascript html-table prototypejs innerhtml


    【解决方案1】:

    将最后一行替换为

    form.select('.audio_channels').each(function(node){
      node.update(template.channelHtml);
    });
    

    这将在实际元素上执行代码,而不是像原始代码那样执行单项数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      相关资源
      最近更新 更多