gpt4 book ai didi

javascript - 在html表格中显示javascript数组

转载 作者:行者123 更新时间:2023-12-02 22:56:42 26 4
gpt4 key购买 nike

我正忙于处理通过数据库中的数据发送的HTML页面。我让数组正常工作并且过滤正确,然后我使用 for 循环在 el 函数中获取对象。控制台日志正确,但我想要显示的页面上的表格在一行上显示一个字母。

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 );
}
}
});



}

当前显示日期,例如:

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

我想要显示的位置:

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

最佳答案

你的第二个循环是问题所在:

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

这是循环遍历日期中的每个字符。您根本不需要第二个循环 - 只需将日期直接添加到:

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

关于javascript - 在html表格中显示javascript数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57951012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com