I am trying to create a group collapsible list view in jquery mobile using data retrieved via SQLite.
My data looks something like this:
Letter | Number
A | 1
A | 2
B | 3
B | 4
C | 5
I want a 'Letter' for each header group which is collapsible, and the various corresponding 'Number' to be a child of each group. Both the header and the subsequent children should be ordered ascending (children within their respective groups).
So essentially the final result in HTML will look something like this:
<div data-role="collapsible-set" id="LetterList" data-filter="true" data-filter-reveal="false">
<div data-role="collapsible" class="collapseclass">
<h2>A</h2>
<ul data-role="listview">
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
</ul>
</div>
<div data-role="collapsible" class="collapseclass">
<h2>B</h2>
<ul data-role="listview">
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
</ul>
</div>
<div data-role="collapsible" class="collapseclass">
<h2>C</h2>
<ul data-role="listview">
<li><a href="#">5</a></li>
</ul>
</div>
</div>
I have attempted creating the headers first, by querying a distinct list of Letter, then inserting the divs:
function querySuccessDistinctLetter(tx, result) {
$('#LetterList').empty();
$.each(result.rows, function (index) {
var row = result.rows.item(index);
$('#LetterList').append('<div data-role="collapsible" class="collapseclass"><h2>' + row['Letter'] + '</h2></div>');
});
}
But now I am stumped as to how I can insert the 'Number' children under each header? Or am I going about this the wrong way?