Before anyone points me to similiar questions here on stackoverflow, I have searched for and read and tried all the solutions that have been provided to no avail. By the way I understand it one would have an empty list like so:
<ul data-role='listview' data-theme='b' data-inset='true' id='resultsList'>
<!-- keep empty for dynamically added items -->
</ul>
Then in your javascript/jquery you'll go like this(bearing in mind I get my data from a JSON object):
var resultLength = jsonObject.results.length;
var listItems = [];
for(var i=0;i<resultLength;i++){
var firstname = jsonObject.results[i].FN;
var lastname = jsonObject.results[i].SN;
//Add result to array
listItems.push("<li><a href='#'>"+firstname+" "+lastname+"</a></li>");
}
//Append array to list and refresh
$('#resultsList').append(listItems.join(' '));
$('#resultsList').listview('refresh');
But... It doesn't work. I'm new to jquery so it might be a real stupid mistake I'm making somewhere. If anyone has an idea of why this isn't working I'd appreciate it! Been struggling with this for 2days now. If any more information is required, please don't hesitate to ask.
Edit - Added JSON as requested
{"results":
[
{ "GUID":"F45B0504-376C-4772-81C2-B920E23E1332",
"I#":"4202265241081",
"FN":"JOHN",
"DOB":"1942-02-26",
"SEX":"M",
"SN":"KHUNOU",
"U#":"VH00041750",
"TYPE":"P"},
{ "GUID":"BB69F24F-424A-4B10-8A48-E94197894855",
"I#":"3909035071082",
"FN":"JOHN E",
"DOB":"1939-09-03",
"SEX":"M",
"SN":"RIVETT CARNAC",
"U#":"VH00156354",
"TYPE":"P"
}
],
"ok":"true"}
var listItems []var listItems = []), but otherwise is your code in a document ready handler? What do you get if you tryalert(listItems.join(' '))just after the loop?console.log(jsonObject)yield, see whatconsole.log(listItems.join(' '))yield. Otherwise your code looks ok