使用Prototype更新表内容时出错

时间:2012-08-07 15:30:18

标签: javascript html-table prototypejs innerhtml

我想在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调用,我需要做什么来设置表的内容?

1 个答案:

答案 0 :(得分:0)

替换最后一行
form.select('.audio_channels').each(function(node){
  node.update(template.channelHtml);
});

这将执行实际元素上的代码,而不是原始代码所执行的单项数组。