AppendTo and "refresh" advice
Hi
I am reading a csv file with php / ajax and creating a list from the file. That works fine.
I am then using: AppendTo to push the html I've built into the <content>
At this point it breaks, as I now know due to the order in which JQM builds the page
Is there some form of "refresh" I need to do to make JQM "see" the html and respond accordingly?
Initally I thought I needed a $('#buglist').listview('refresh'); << but
a) I am not sure where to put it
b) There is also a collapsed list being built dynamically.
My code is:
- <!DOCTYPE html>
- <html>
- <head>
- <title>Bacterium Antibiograms reading csv</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
- <script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
- <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
- </head>
- <body>
- <div data-role="page">
- <div data-role="header">
- <h1>Bacterium Antiobiograms</h1>
- </div>
-
- <script type="text/javascript">
-
- $(document).ready(function() {
- $.ajax({
- type: 'GET',
- url: 'get-csv.php',
- data: null,
- success: function(text) {
-
- var fields = text.split(/\n/);
- fields.pop(fields.length-1);
- var headers = fields[0].split(','), markup = '';
-
- var data = fields.slice(1, fields.length);
-
- for(var j = 0; j < data.length-2; j += 1) {
-
- var dataFields = data[j].split(',');
-
- markup +='<div data-role="collapsible" data-theme="b" data-content-theme="c">';
-
- markup +='<h2>' + dataFields[1] + '</h2>';
- markup +='<id = "buglist" ul data-role="listview">';
- markup +='<li>' + headers[2] +"........" + dataFields[2] + '</li>';
- markup +='<li>' + headers[3] +"........" + dataFields[3] + '</li>';
- markup +='<li>' + headers[4] +"........" + dataFields[4] + '</li>';
- markup +='<li>' + headers[5] +"........" + dataFields[5] + '</li>';
- markup +='</ul>';
-
- markup +='</div>';
-
- }
-
- $('.bugs').append(markup);
-
- }
-
- });
- });
-
- </script>
-
-
- <div data-role="content" class="bugs">
- </div>
-
- <div data-role="footer">
- version 0.5
- </div>
- </div>
- </body>
- </html>
This must be easier than I am making it......
Any advice on refreshing the <content> greatly received.
I have read the documentation on dynamic pages and I cant adapt the example to my case -- must be getting old.
Cheers
Glen