How to create a category wise listview dynamically using jquery?

How to create a category wise listview dynamically using jquery?

i'm trying to get the category wise listview dynamically using jquery. I have xml file with all content in that file i have different category's.

Html file:

<div data-role="page" id="home"> <div data-role="header" data-theme="a" data-position="fixed"> <h1 id="title"></h1> </div> <div data-role="content" data-transition="slide" data-inset="true"> <ul class="list" id="section" data-role="listview" data-filter="true"> </ul> </div> </div>




xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sections> <section count="6" name="Alphabets" order="1"> <content order="1">A</content> <content order="2">B</content> <content order="3">C</content> <content order="4">D</content> <content order="5">E</content> <content order="6">F</content> </section> <section count="4" name="Numbers" order="2"> <content order="7">1</content> <content order="8">2</content> <content order="9">3</content> <content order="10">4</content> </section> </sections>




My code:

  1. $(xml).find('section').each(function () {
  2.     var section = $(this).attr("name");
  3.     var order = $(this).attr("order");
  4.     var count = $(this).attr("count");
  5.     $(xml).find('section[order="' + order + '"] content').each(function () {
  6.         var content = $(this).text();
  7.         var seq = order + '' + $(this).attr('order');
  8.         var file = $(this).attr('file');
  9.     $("#section_list").append('<li data-role="list-divider" sec="'+ section +'"><a href="#chapter" class="style" id="' + order + '"><b>' + content + '</b></a> </li>');
  10. $("#section_list").listview({
  11.     autodividers: true,
  12.             autodividersSelector: function (li) {
  13.                 var out = li.attr('sec');
  14.                 return out;
  15.             }
  16.         }).listview('refresh');
  17.     });
  18.             });
  19.             });



I tried like this but this not working i dont knw where i did the mistake.Can any one help me out from this.

Thanks in Advance.