I develop an android native application using phonegap and jquery mobile. I've made a function to create a listview style dynamically using looping for..
. When I run the function for the first time, it works, the listview style is working, and match with the content. but when I press back button and run the function again, the style change (the listview style is gone) but the content still there. is my function wrong? how to solve this problem?
the screenshoot for more explanation:
the codes for more detail:
function detail(kodenegara, koderesult)
{
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "http://10.80.3.73/webservice/Service1.svc/json/weeklyflash/"+kodenegara,
dataType: "json",
success:function(data){
var result = koderesult;
maks = -1;
for(i = 0; i < data[result].length; i++) {
if(data[result][i].bulan > maks)
maks = data[result][i].bulan;
}
var loop_tipe = countTypesForBulan(data[result], maks);
var innerHtml = "";
for (i = 0; i < loop_tipe; i++){
a=i+loop_tipe;
b=a+loop_tipe;
innerHtml +=
"<div data-role='collapsible' data-collapsed='true'>"+
"<h3>"+data[result][i].type+"</h3>"+
"<table width='100%' border='1'>"+
"<tr>"+
"<td> </td>"+
"<td style='text-align: center'>"+data[result][i].bulan+"/2012</td>"+
"<td style='text-align: center'>"+data[result][a].bulan+"/2012</td>"+
"<td style='text-align: center'>"+data[result][b].bulan+"/2012</td>"+
"</tr>"+
"<tr>"+
"<td>Cash</td>"+
"<td style='text-align: right'>"+data[result][i].uang+"</td>"+
"<td style='text-align: right'>"+data[result][a].uang+"</td>"+
"<td style='text-align: right'>"+data[result][b].uang+"</td>"+
"</tr>"+
"<tr>"+
"<td>Qty</td>"+
"<td style='text-align: right'>"+data[result][i].total+"</td>"+
"<td style='text-align: right'>"+data[result][a].total+"</td>"+
"<td style='text-align: right'>"+data[result][b].total+"</td>"+
"</tr>"+
"</table>"+
"</div>";
}
$('#tipe').html(innerHtml);
$.mobile.changePage("#detail", "slide", false, true);
//show the page
},
error: function () {
alert("ERROR");
}
});
}
function countTypesForBulan(resultArray, bulanVal) {
var i,
types,
count = 0;
for (i=0, types = {}; i < resultArray.length; i++)
if (resultArray[i].bulan === bulanVal && !types[resultArray[i].type]) {
types[resultArray[i].type] = true;
count++;
}
return count;
}
{"GetReportIdResult":[{"bulan":"4","total":"1728","type":"CHEESE1K","uang":"8796383"},{"bulan":"4","total":"572476","type":"ESL","uang":"5863408410"},{"bulan":"5","total":"4761","type":"CHEESE1K","uang":"134877865"},{"bulan":"5","total":"648663","type":"ESL","uang":"6645764498"},{"bulan":"6","total":"5762","type":"CHEESE1K","uang":"293393832"},{"bulan":"6","total":"594942","type":"ESL","uang":"6088671790"},]}
\$\endgroup\$