我在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
?我该如何设置?