У меня есть такой массив:
var arr = [
{ Group: 'Fruits', Name: 'Apple' },
{ Group: 'Fruits', Name: 'Pears' },
{ Group: 'Veggies', Name: 'Tomatoes' },
{ Group: 'Veggies', Name: 'Carrots' }
];
Я хочу создать флажки для каждой группы в моем контейнере HTML
, поэтому я получаю вывод, подобный этому:
<div id="container">
<h4>
Fruits</h4>
<ul id="Fruits">
<li>
<input type="checkbox" name="Apples" id="Fruits-Apples" /><label>Apples</label></li>
<li>
<input type="checkbox" name="Pears" id="Fruits-Pears" /><label></label>Pears</li>
</ul>
<h4>
Veggies</h4>
<ul id="Veggies">
<li>
<input type="checkbox" name="Tomatoes" id="Veggies-Tomatoes" /><label>Tomatoes</label></li>
<li>
<input type="checkbox" name="Carrots" id="Veggies-Carrots" /><label>Carrots</label></li>
</ul>
</div>
Каков наилучший способ сделать это с помощью jquery?