我在 JSON 中有一组这样的对象:
[
{
"Name":"John Doe",
"Age":46,
"Hometown":"Anytown, USA",
},
{
"Name":"Jane Q. Public",
"Age":23,
"Hometown":"Mayberry, NC",
},
{
"Name":"Andrew Andrews",
"Age":62,
"Hometown":"New York, NY"
},
]
我需要将其转换为具有以下格式的 HTML:
<div class="person">
<h2>Name</h2>
<p class="name">John Doe</p>
<h2>Age</h2>
<p class="age">46</p>
<h2>Hometown</h2>
<p class="hometown">Anytown, USA</p>
</div>
...
最好为此使用jQuery.map()
吗?或者each
?我应该如何设置它?