本文介绍了从数组生成HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据格式如下所示......(示例一)这是一个数组。基于数据,我需要通过自定义条件生成一个html表...比如,表头将是day1,2 ,3,4,5,6及以下数组必须根据条件添加每个标题...我已经提供了详细信息供参考



var array = [{day:1,summary:proge1},

{day:1,summary:proge2},

{day:1,summary:proge3},

{day:2,summary:Tues1},

{day:2,summary:Tues2},

{day:2,summary:Tues3},

{ day:3,summary:Wed1},

{day:3,summary:Wed2},

{day :3,摘要:Wed3},

{day:4,summary:Thur1},

{day: 4,摘要:Thur2},

{day:5,summary:Fri1},

{day:6, summary:Sat1}]

我想基于这些数据生成一个html表,它应该显示为低..有人请建议我如何做到这一点..





















Day1 Day2 Day3 第4天 第5天 第6天


输出:



----------------------- -----------------------

Day1 | Day2 Day3 Day4 Day5 Day6

---- -------------------------------------------

proge1 Tue1 Wed1 Thur1 Fri1 Sat1



proge2 Tue2 Wed2 Thur2

proge3 Tue3 Wed3



我尝试过:



这里是wat我做的....









$(function(){

var json = [];

var tr, start = 0;

console.log('这里json check here',json);

for(var i = 0;我< json.length; i ++){

tr = $('');

tr.append(+ json [i] .summary +);

$('table')。append(tr);

}

}},





但是我在考虑如何为每个td调用这个函数....说...为每个td分配一些值,如1,2,3,4并将该值传递给函数和得到每个td所需的数据.....专家...我是html的新手请告知你是否有任何想法

I have data in Array format as below... (sample one) this is an array..Based on data , I need to generate a html table by custom condition... say, table header will be day1,2,3,4,5,6 and below array has to be based for each header to add row based on the conditions... I have given the details for reference

var array= [{"day":1,"summary":"proge1"},
{"day":1,"summary":"proge2"},
{"day":1,"summary":"proge3"},
{"day":2,"summary":"Tues1"},
{"day":2,"summary":"Tues2"},
{"day":2,"summary":"Tues3"},
{"day":3,"summary":"Wed1"},
{"day":3,"summary":"Wed2"},
{"day":3,"summary":"Wed3 "},
{"day":4,"summary":"Thur1"},
{"day":4,"summary":"Thur2"},
{"day":5,"summary":"Fri1"},
{"day":6,"summary":"Sat1"}]
I want to generate a html table based on this data such that it should display as below..can someone please suggest me how to accomplish this..










Day1Day2Day3Day4Day5 Day6

output:

----------------------------------------------
Day1 |Day2 Day3 Day4 Day5 Day6
-----------------------------------------------
proge1 Tue1 Wed1 Thur1 Fri1 Sat1

proge2 Tue2 Wed2 Thur2
proge3 Tue3 Wed3

What I have tried:

here is wat i did....




$(function () {
var json = [];
var tr,start=0;
console.log('here json check here',json);
for (var i = 0; i < json.length; i++) {
tr = $('');
tr.append("" + json[i].summary + "");
$('table').append(tr);
}
}},


But I am thinking how to call this function for each td....say... assign some value for each td like 1,2,3,4 and pass that value to function and get required data for each td.....Experts... I am new to html please advise if you have any idea

推荐答案




这篇关于从数组生成HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 12:19