admin管理员组文章数量:1022434
I am trying to create a html table using node.js. I will send JSON data from the server to the HTML page. Then I am thinking of turning this JSON into a table but I couldn't run any of the methods on the internet.
My problems are exactly like these:
1- My table contains various css classes. How do I add these classes to the table I will create with Javascript?
2- I want to use template engines like PUG, EJS but only for the table. Can I embed PUG or EJS code inside the normal html page?
In short, what is the easiest way to dynamically create a table for node.js? (without losing the css design)
I am trying to create a html table using node.js. I will send JSON data from the server to the HTML page. Then I am thinking of turning this JSON into a table but I couldn't run any of the methods on the internet.
My problems are exactly like these:
1- My table contains various css classes. How do I add these classes to the table I will create with Javascript?
2- I want to use template engines like PUG, EJS but only for the table. Can I embed PUG or EJS code inside the normal html page?
In short, what is the easiest way to dynamically create a table for node.js? (without losing the css design)
Share Improve this question asked Jan 21, 2020 at 20:09 Pehr SibusisoPehr Sibusiso 9122 gold badges17 silver badges32 bronze badges 2- is jquery an option? nodejs is serverside, you can't just "create" html pages with it. Get the JSON through AJAX and dynamically create a table. – Sam Leurs Commented Jan 21, 2020 at 20:13
- I think this would be the best if I make the table part of the HTML page with PUG or EJS. but if not, i would like to see your answer. Can you share an example with me? – Pehr Sibusiso Commented Jan 21, 2020 at 20:17
1 Answer
Reset to default 2As your question is very generic, I am assuming some things & providing a solution
Let's say you get json array from server as below
[
{
name:'John',
surname:'Doe',
age:25
},
{
name:'Jane',
surname:'War',
age:21
},
{
name:'Shane',
surname:'Meyer',
age:22
}
]
You have HTML as below
<table id="my_table">
<tr>
<th>Name</th>
<th>Surname</th>
<th>Age</th>
</tr>
</table>
Write javascript as below to add rows inside table
forEach(let row in array) {
$('#my_table').append(`<tr>
<td>${row.name}</td>
<td>${row.surname}</td>
<td>${row.age}</td>
</tr>`);
}
I am trying to create a html table using node.js. I will send JSON data from the server to the HTML page. Then I am thinking of turning this JSON into a table but I couldn't run any of the methods on the internet.
My problems are exactly like these:
1- My table contains various css classes. How do I add these classes to the table I will create with Javascript?
2- I want to use template engines like PUG, EJS but only for the table. Can I embed PUG or EJS code inside the normal html page?
In short, what is the easiest way to dynamically create a table for node.js? (without losing the css design)
I am trying to create a html table using node.js. I will send JSON data from the server to the HTML page. Then I am thinking of turning this JSON into a table but I couldn't run any of the methods on the internet.
My problems are exactly like these:
1- My table contains various css classes. How do I add these classes to the table I will create with Javascript?
2- I want to use template engines like PUG, EJS but only for the table. Can I embed PUG or EJS code inside the normal html page?
In short, what is the easiest way to dynamically create a table for node.js? (without losing the css design)
Share Improve this question asked Jan 21, 2020 at 20:09 Pehr SibusisoPehr Sibusiso 9122 gold badges17 silver badges32 bronze badges 2- is jquery an option? nodejs is serverside, you can't just "create" html pages with it. Get the JSON through AJAX and dynamically create a table. – Sam Leurs Commented Jan 21, 2020 at 20:13
- I think this would be the best if I make the table part of the HTML page with PUG or EJS. but if not, i would like to see your answer. Can you share an example with me? – Pehr Sibusiso Commented Jan 21, 2020 at 20:17
1 Answer
Reset to default 2As your question is very generic, I am assuming some things & providing a solution
Let's say you get json array from server as below
[
{
name:'John',
surname:'Doe',
age:25
},
{
name:'Jane',
surname:'War',
age:21
},
{
name:'Shane',
surname:'Meyer',
age:22
}
]
You have HTML as below
<table id="my_table">
<tr>
<th>Name</th>
<th>Surname</th>
<th>Age</th>
</tr>
</table>
Write javascript as below to add rows inside table
forEach(let row in array) {
$('#my_table').append(`<tr>
<td>${row.name}</td>
<td>${row.surname}</td>
<td>${row.age}</td>
</tr>`);
}
本文标签: javascriptNodejsHow to create html tablesStack Overflow
版权声明:本文标题:javascript - Node.js - How to create html tables? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745573182a2156860.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论