2013-12-22 33 views

回答

1

該解決方案與Android版本完全不同。

之後的步驟是必要的:

  • 負載從localstore作爲二進制數據的圖像;

  • 將它置於編碼的img元素的「src」屬性中;

代碼:

var fileName = 'myappname/test.png'; 

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFail); 

function onFileSystemSuccess (fileSystem) { 
    fileSystem.root.getFile(fileName, null, gotFileEntry, onFail); 
} 

function gotFileEntry(fileEntry) { 
    fileEntry.file(onGotFile, onFail); 
} 

function gotFile(onGotFile) { 
    var reader = new FileReader(); 
    reader.onloadend = function (evt) { 
    $('#outerDiv').html('<img src="' + evt.target.result + '" />'); 
    }; 
    reader.readAsDataURL(file); 
} 

function onFail(evt) { 
    console.log('error: ' + evt.target.error.code); 
} 
相關問題