Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.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 在Angular 8中格式化表格中的数据不起作用_Javascript_Html_Json_Angularjs - Fatal编程技术网

Javascript 在Angular 8中格式化表格中的数据不起作用

Javascript 在Angular 8中格式化表格中的数据不起作用,javascript,html,json,angularjs,Javascript,Html,Json,Angularjs,我是个新手。在这里,我试图格式化表上显示的JSON数据。这是我试图实现的,对于空行,我用连字符填充,大于25的值用红色填充单个单元格背景,介于20和25之间的值用黄色填充,但由于一些奇怪的原因,我的表没有完全格式化,这就像它没有检测ngAfterViewInit()函数一样,当我尝试获取所有列的平均值时,我得到的结果是所有列的NaN 我的component.ts文件 @ViewChild('myTable', {static: false}) myTable: ElementRef; ngA

我是个新手。在这里,我试图格式化表上显示的JSON数据。这是我试图实现的,对于空行,我用连字符填充,大于25的值用红色填充单个单元格背景,介于20和25之间的值用黄色填充,但由于一些奇怪的原因,我的表没有完全格式化,这就像它没有检测ngAfterViewInit()函数一样,当我尝试获取所有列的平均值时,我得到的结果是所有列的NaN

我的component.ts文件

@ViewChild('myTable', {static: false}) myTable: ElementRef;

 ngAfterViewInit() {

    var table = this.myTable.nativeElement;
    var row;
    var cell;
    var j = 1;
    var r = 0;
    var t = 0;
    //console.log(table);
    if (table !== null) {
      while (row = table.rows[r++]) {
        var c = 0;
        while (cell = row.cells[c++]) {
          var cellValue = cell.innerHTML;
          //cell.innerHTML='[Row='+r+',Col='+c+']'; // do sth with cell
          if (c === 5 && cellValue > 25) {
            cell.style.background="#FF0000";
          } else if (c === 5 && cellValue >= 10 && cellValue < 25) {
            cell.style.background="#FFFF00";
          }

        }
      }
      //getting the average value of each column
      var colL = table.rows.length - 1;
      //console.log(table.rows[1].cells.length);
      for (j = 1; j < table.rows[1].cells.length; j++) {
        var sumVal = 0;
        for (var i = 1; i < table.rows.length; i++) {
          if (i < colL) {
           //console.log(table.rows[i].cells[1].innerHTML);
            if (Number.isInteger(parseInt(table.rows[i].cells[j].innerHTML)) === true) {
              sumVal = sumVal + parseFloat(table.rows[i].cells[j].innerHTML);
            } else {
              table.rows[i].cells[j].value = "-";
              table.rows[i].cells[j].style.backgroundColor = "#FFFF00";
            }
          }
         // console.log(table.rows[colL].cells[table.rows.length - 1].innerHTML);
        }

        //Setting the last cell with the avirrage value
        if (table.rows[colL].cells[j] !== table.rows[colL].cells[table.rows[1].cells.length - 2]) {
          var ans = (sumVal / (table.rows.length - 2)).toFixed(2);
          table.rows[colL].cells[j].innerHTML = ans;
        } else
          table.rows[colL].cells[j].innerHTML = sumVal;

        //Taking out all cells with zore totals
        if (parseFloat(ans) === 0) {
          for (t = 0; t <= colL; t++) {
            table.rows[t].cells[j].style.display = 'none';
          }
        }

      }
    }
  }
}
@ViewChild('myTable',{static:false})myTable:ElementRef;
ngAfterViewInit(){
var table=this.myTable.nativeElement;
var行;
var细胞;
var j=1;
var r=0;
var t=0;
//控制台日志(表);
如果(表!==null){
while(row=table.rows[r++]){
var c=0;
while(cell=row.cells[c++]{
var cellValue=cell.innerHTML;
//cell.innerHTML='[Row='+r+',Col='+c+']';//用cell做某事
如果(c==5&&cellValue>25){
cell.style.background=“#FF0000”;
}如果(c==5&&cellValue>=10&&cellValue<25)则为else{
cell.style.background=“#ffffff00”;
}
}
}
//获取每列的平均值
var colL=table.rows.length-1;
//console.log(table.rows[1].cells.length);
对于(j=1;j <div class="panel-body" >
        <div class="table-responsive">
          <table class="table table-hover" #myTable>
            <thead>
<tr class="even gradeC" style="text-align:center" ng-repeat="home in homeurban"
                *ngFor="let home of homeurban">
              <td class="infos" style="position: absolute;  top: auto;  width: 100.5px;">{{home.teamNumber}}</td>