looking for way to auto generate a listview for JQuery-Mobile from any json call. I assume I would load results into an array and iterate through for key/value and populate results to a ul with the li's created based on the numbers of results... can't figure out how to get length of the keys and then loop through them to populate <li>
with the key and val. Would like to have it work without having to know any of the json values.
here is a starting point that is not working:
$(document).ready(function(){
$.getJSON("json_mdb.php", function(data){
for (var i = 0; i < data.length; i++) {
$.each(data[i], function(key, val) {
//console.log(key + ":" + val);
$('#myUL').html("<li>" + key + " : " + val + "</li>");
});
}
});
});
<div data-role="page" id="index" data-theme="d">
<div data-role="content">
<div id="inventory">
<ul data-role='listview' id='myUL' data-inset='true' class='ui-listview ui-listview-inset ui-corner-all ui-shadow'>
</ul>
</div>
</div>
</div>
Example JSON:
[{"LastName":"Doe","FirstName":"John","ID":"DJ0000"},{"LastName":"Doe","FirstName":"Jane","ID":"DA0000"}]