简体   繁体   English

在html表中显示javascript数组

[英]display javascript array in html table

I am busy with an HTML page that I have sent through data from a database . 我正忙于通过database数据发送的HTML页面。 I have the array working and I am filtering correctly, then I used a for loop to get the object in an el function. 我的数组正常工作,并且过滤正确,然后使用了for循环在el函数中获取对象。 the console log's correctly, but the table on the page where I would like to display does a letter on a line. 控制台日志正确,但是我要显示的页面上的表在一行上写了一个字母。

JAVASCRIPT

function go(){
  var startd = document.getElementById('startdate').value+" 00:00";
  var stopd = document.getElementById('stopdate').value;
  var array = [<%items.forEach(function(item, index){%>{date:"<%= item.Expr1000%>", inout:"<%= item.CHECKTYPE%>", sn:"<%= item.sn%>"},<% });%>{date:"stop"}];
var check = array.filter(function(el){
return el.date >= startd &&
       el.date <= stopd &&
       el.inout &&
       el.sn;

});

check.forEach(function(el){
console.log(el.date);
var table = $('#set');
 var row, cell;
 for(var i=0; i<el.date.length; i++){
 row = $( '<tr />' );
 table.append( row );
 for(var j=0; j<el.date[i].length; j++){
 cell = $('<td>'+el.date[i][j]+'</td>');
 row.append( cell );
 }
 }
});



}

Currently displays the date like: 当前显示的日期如下:

2
0
1
9
-
0
8
-
1
5

0
7
:
0
0
:
2
1
2
0
1
9
-
0
8
-
1
5

0
7
:
0
0
:
3
0

Where I would like to display as: 我想显示为:

 yyyy-mm-dd hh:mm:ss
 yyyy-mm-dd hh:mm:ss

Your second loop is the problem: 您的第二个循环是问题:

for(var j=0; j<el.date[i].length; j++){
  cell = $('<td>'+el.date[i][j]+'</td>');
  row.append( cell );
}

That is looping over every character in the date. 那就是遍历日期中的每个字符。 You don't need the second loop at all—just add the date directly to the row : 您根本不需要第二个循环,只需将日期直接添加到该row

cell = $('<td>'+el.date[i]+'</td>');
row.append( cell );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM