Take the 2-minute tour ×

I'm using jQuery mobile and Phonegap to implement an iPhone app and want to implement a list view, without using hard coded data statistically.

<ul data-role="listview" data-inset="true" class="ui-listview">

Not like the above hard code.

I need to create an object like an array with list of numbers (one, two, three, four, five, etc.), and using that numbers array I want to populate in to a list view. How is it possible to create and use an array in jQuery mobile to display content in a list view.

share|improve this question
well, what is it that you don't know how to do? create the array? receive the data? create the list html? refresh the widget? –  Th0rndike Jun 1 '12 at 11:22
yes.. but know create the list view in jQuery mobile but with hard code as shown above –  Vijay Jun 1 '12 at 11:49
Vijay, please don't post duplicate content on StackOverflow. This just clutters up the homepage. In the faq, it explains that when you edit your question to improve it, it gets bumped back up to the top of the list; therefore, there is no need to post duplicates. Hope this helps! –  jmort253 Jun 2 '12 at 4:23
add comment

1 Answer

up vote 0 down vote accepted

You want to do something like this:

for (var i=0; i < NUMBERS.length; i++) {
    $('#idofmylist').append($('<li/>', {    
            'id': id

You'll need to give you "ul" an id that you can reference to add the "li"'s using jQuery's append.

share|improve this answer
at where in index.html page? or anywhare else –  Vijay Jun 1 '12 at 13:35
Well you have to call the JavaScript function when you want to populate the list. –  Simon MacDonald Jun 1 '12 at 16:29
add comment

Your Answer


