I have json data
I’ve taken the first set of data and written it to one ul.
I want to split the remaining data into 2 equal chunks and write to two other uls.
How do I split the remaining json after the initial index == 0?
my js code:
$("#storeList").append('<ul class="storeListLeft"></ul>');
$("#storeList").append('<ul class="storeListRight"></ul>');
//run store json data and append to storeList div
var object;
$.getJSON('xml/storeList.json', function(json) {
object = json;
$.each(object.storeList.state, function(index, value) {
var list;
if(index == 0) {
list = $('.storeListLeft');
} else {
list = $('.storeListRight');
}
listItem = $('<li/>'),
html = listItem.append($('<h3/>').text(this.stateName));
$.each(this.store, function() {
listItem.append($('<a />').attr('href', this.storeURL).attr('class', 'storeInactive').attr('id', this.storeID).text(this.storeName));
});
list.append(html)
});
}); //end json render
CUrrent output:
<ul class="storeListLeft">
<li>
<h3>state Name</h3>
<a>store Name</a>
</li>
</ul>
<ul class="storeListRight">
<li>
<h3>state Name</h3>
<a>store Name</a>
<a>store Name</a>
<a>store Name</a>
</li>
<li>
<h3>state Name</h3>
<a>store Name</a>
</li>
</ul>
my desired output is to still assign the first item to the storeListLeft, and then split the remaining data and assign the chunks to 2 separate uls
so something like this:
<ul class="storeList_1"> //which is index == 0
<li>
<h3>state Name</h3>
<a>store Name</a>
</li>
</ul>
<ul class="storeList_2"> //2 & 3 are the split of the remainder after index == 0
<li>
<h3>state Name</h3>
<a>store Name</a>
<a>store Name</a>
<a>store Name</a>
</li>
<li>
<h3>state Name</h3>
<a>store Name</a>
</li>
</ul>
<ul class="storeList_3">
<li>
<h3>state Name</h3>
<a>store Name</a>
<a>store Name</a>
<a>store Name</a>
</li>
<li>
<h3>state Name</h3>
<a>store Name</a>
</li>
</ul>
Before the first loop break the states into the objects you want:
Here is a function to generate the markup:
And calling the function: