Question

I am using a listview to display an rss feed type feed, I add an item on click to an arraylist, and loop through that arraylist to dynamically create a listview.

I would like to achieve an rss feed style with the most recent item on top, and keep appending elements,to it. is this possible with the jQueryMobile listview widget?

Was it helpful?

Solution

You can easily accomplish what you want by prepending items to your listview instead of appending them and then calling the listview's refresh method.

For example

  $('#myList').prepend($('<li>' + item + '</li>')).listview('refresh');

Here's an example jsBin

If you need to resort your listview at some point you can detach (so you don't lose any attached events) all the items in the listview and then reattach them based on whatever sort order you need.

For example

var $myList = $('#myLis');
$myList.find('li').detach();

var len = myList.length;
while (len--) {
  var item = myList[len];
   $myList.prepend($('<li>' + item + '</li>'));
}
$myList.listview('refresh');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top