javascript - Dynamically populate listview in jQuery mobile based on if file exists on phone -


this start of code. populates unordered list json file. tried using cordova filereader without luck.

document.addeventlistener("deviceready", ondeviceready, false); function ondeviceready() {     alert("got deviceready");      var reader = new filereader();     var filesource = cordova.file.externaldatadirectory;      $.getjson( "links.json", function( data ) {              $.each( data, function( key, val ) {              var $li = $("<li><a href='#'>"+val.title+"</a></li>");              reader.onloadend = function(evt) {                  if(evt.target.result == null) {                 $li.find("a").on("click", function(){ downloadpdf(val.title,val.url); });                 } else {                 $li.find("a").on("click", function(){ openpdf(val.title); });                 }             };              // going check if file exists             reader.readasdataurl(filesource + val.title + ".pdf");              $("#linklist").append($li);             $("#linklist").listview('refresh');             });      });   } 

as can see, example adds list items downloadpdf(title, url) function. if exists, want list item call function openpdf(title) instead. files saved in cordova.file.externaldatadirectory + title + ".pdf".

this code doesn't add items list.

you can use file plugin check if file exists

var reader = new filereader(); var filesource = <here file path>  reader.onloadend = function(evt) {      if(evt.target.result == null) {        // if receive null value file doesn't exists     } else {         // otherwise file exists     }          };  // going check if file exists reader.readasdataurl(filesource);  

Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -