I have a json data format:
[{'note':'n1','subject':'subject1','value':10},{'note':'n3','subject':'subject2','value':19}];
from that I have generate two arrays one for header column cols
and other for row rows
let notes = [{'note':'n1','subject':'subject1','value':10},{'note':'n3','subject':'subject2','value':19}];
let cols = ['n1', 'n2', 'n3'];
let rows = ['subject1', 'subject2'];
let matrix = Array(cols.length).fill(Array(rows.length).fill(0));
for(const x of notes){
let {note, subject, value} = x;
matrix[cols.indexOf(note)][rows.indexOf(subject)] = note;
}
console.log(matrix)
预期结果:
[[10,0,0],[0,0,19]]
但我的目标是将其渲染为HTML
表,如下所示:
Subj\Note | Note1 | Note2 | Note3 |
---|---|---|---|
Subj1 | 10 | 0 | 0 |
subj2 | 0 | 0 | 19 |
我怎么能做到这一点,非常感谢您的任何建议或帮助!