Home > front end >  Ask: N columns show the data
Ask: N columns show the data

Time:09-22

Want to achieve:

The current code:
Var data=https://bbs.csdn.net/topics/[{" NAME ":" A ", "Lei" : [{" ID ":" A1 "}, {" ID ":" A2 "}, {" ID ":" A3 "}, {" ID ":" A4 "}, {" ID ":" A5 "}, {" ID ":" A6}]},
{" NAME ":" B ", "Lei" : [{" ID ":" B1 "}, {" ID ":" B2 "}, {" ID ":" B3 "}, {" ID ":" B4 "}, {" ID ":" B5 "}, {" ID ":" B6}]}];
Var s=0;
Var U=0;
Var ONELie=2;
Var TOWLie=5;
Var SU="& lt; The table border='1' width="100%" & gt;"
SU +="& lt; Tr align='center' & gt;"
for(var i=0; i If (+ + s % ONELie==1) {+="SU & lt;/tr> SU +="& lt; Td height='40' colspan='" + TOWLie + "' & gt; " + data [I]. NAME + "& lt;/b> ";
}
SU +="& lt;/tr> /* */
for(var i=0; i //-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
For (var K=0; K & lt; Data [I]. Lei. Length; K++) {
If (+ + U % TOWLie * ONELie==1) {
SU +="& lt;/tr> }
SU +="& lt; Td align="center & gt;" + data [I]. Lei [K]. ID + "& lt;/td> ";
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
SU +="& lt;/tr>"
}

SU +="& lt;/table>"
$(" # tite "). Append (SU);

execution always cannot be classified according to the list above, please help to look at, thank you!

CodePudding user response:

What do you mean, words clear point,

CodePudding user response:

 & lt; ! DOCTYPE html> 

<meta charset="utf-8" & gt;
<meta name="viewport" content="width=device - width, initial - scale=1.0" & gt;
Document

<body>

<script SRC="https://bbs.csdn.net/topics/jquery-3.3.1.js" & gt; </script>
<script>
$(function () {
Var data=[https://bbs.csdn.net/topics/
{" NAME ":" A ", "Lei" : [{" ID ":" A1 "}, {" ID ":" A2 "}, {" ID ":" A3 "}, {" ID ":" A4 "}, {" ID ":" A5 "}, {" ID ":" A6}]},
{" NAME ":" B ", "Lei" : [{" ID ":" B1 "}, {" ID ":" B2 "}, {" ID ":" B3 "}, {" ID ":" B4 "}, {" ID ":" B5 "}, {" ID ":" B6 "}, {" ID ":" B7}]},
{" NAME ":" C ", "Lei" : [{" ID ":" C1 "}, {" ID ":" C2 "}, {" ID ":" C3 "}, {" ID ":" C4 "}, {" ID ":" C5 "}, {" ID ":" C6 "}, {" ID ":" the C7}]},
];
Var colNum=3;
Var HTML="& lt; The table border='1' width="100%" & gt; Data. The forEach (item=& gt; {
HTML +="& lt; Td height='40' colspan='" + + "colNum' & gt; " + item. The NAME + "& lt;/b> ";
});
HTML +="& lt;/tr> Var rowNum=0;
Data. The forEach (group=& gt; {
RowNum=group. Lei. Length/colNum & gt; RowNum? Math. Ceil (group. Lei. Length/colNum) : rowNum;
});
for (var i=0; i HTML +="& lt; Tr align='center' & gt; ";
Data. The forEach (item=& gt; {
For (var j=0; J & lt; ColNum; J++) {
HTML +="& lt; Td>" ColNum + + (item. Lei [I * j]? Item. Lei [I * colNum + j] ID: "") +" & lt;/td> ";
}
});
HTML +="& lt;/tr> ";
}
HTML +="& lt;/table>"
$(" # box "). Append (HTML);
});
</script>


This way I think it's not easy

CodePudding user response:

Thank nian_cj, but there is a not understand, can you tell me the "group. Lei. Length/colNum & gt; RowNum? Math. Ceil (group. Lei. Length/colNum) : rowNum;" What's that mean?

CodePudding user response:

Three expression expression? The value of the expression is true value: false
  • Related