Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
刷新javascript中每次调用的行_Javascript_Html - Fatal编程技术网

刷新javascript中每次调用的行

刷新javascript中每次调用的行,javascript,html,Javascript,Html,我正在用HTML构建一个表 使用JavaScript,我根据数组中对象的数量追加了许多表行,然后追加了单元格。这很好,下面是代码: 函数生成\u表过滤\u数据{ 过滤的_data.forEachobj=>{ //为每个对象创建表行 var row=tbody.appendtr; Object.entriesobj.forEachfunctionx{ //在当前行中创建单元格。 var cell=row.appendtd; //给单元格一个值 cell.textx[1]; }; } ; 日期 城

我正在用HTML构建一个表

使用JavaScript,我根据数组中对象的数量追加了许多表行,然后追加了单元格。这很好,下面是代码:

函数生成\u表过滤\u数据{ 过滤的_data.forEachobj=>{ //为每个对象创建表行 var row=tbody.appendtr; Object.entriesobj.forEachfunctionx{ //在当前行中创建单元格。 var cell=row.appendtd; //给单元格一个值 cell.textx[1]; }; } ; 日期 城市 状态 国 形状 期间 评论
在这种情况下,您需要首先清除表体的html,如:

document.getElementsByTagName("tbody")[0].innerHTML='';
然后是你的旧程序:

filtered_data.forEach((obj => {
    // Create table rows for each object
    var row = tbody.append("tr");
    Object.entries(obj).forEach(function(x){
        // Create cell within current row.
        var cell = row.append("td");
        // give cell a value
        cell.text(x[1]);
    });
}));
简单的

resetTable(document.getElementById('TEMPID'));

function resetTable(tableSelector) {
  var tableTBodySelector = tableSelector.getElementsByTagName('TBODY')[0];
  while (tableTBodySelector.hasChildNodes()) {
  tableTBodySelector.removeChild(tableTBodySelector.lastChild);
  }
}


<table id="TEMPID">
    <thead>
      <tr>
        <th class="table-head">Date</th>
        <th class="table-head">City</th>
        <th class="table-head">State</th>
        <th class="table-head">Country</th>
        <th class="table-head">Shape</th>
        <th class="table-head">Duration</th>
        <th class="table-head">Comments</th>
      </tr>
    </thead>
    <tbody></tbody>
</table>

如何调用build_表?什么是filterd_数据?请修复语法错误,将snake_大小写更改为camelCase,并提供筛选的_数据以生成。在调用build_表之前清除表中的行