我有像繪製應用程序。用戶可以保存項目並加載它們。當我第一次加載一個文件(例如project1.leds)在應用程序中進行一些更改但不保存它,然後再次加載相同的文件(project1.leds)時,什麼都不會發生。我不能一次加載同一個文件。如果我加載其他文件,它的工作。Filereader - 再次上傳相同的文件不起作用
代碼:
$("#menu-open-file").change(function(e){
var data=[];
var file = null;
file = e.target.files[0];
console.log(file)
var reader = new FileReader();
reader.onload = function(e){
data=JSON.parse(reader.result);
x=data[0].SIZE[0];
y=data[0].SIZE[1];
if(x==15) x=16;
if(x==30) x=32;
if(x==60) x=64;
if(y==15) y=16;
if(y==30) y=32;
if(y==60) y=64;
createLeds(x,y,data,false,false);
clearActiveTools();
var svg = $('#contener').find('svg')[0];
svg.setAttribute('viewBox','0 0 ' + x*20 + ' ' + y*20);
$("#contener").css("width",x*20).css("height",y*20);
$("#contener").resizable({
aspectRatio: x/y,
minHeight: 200,
minWidth: 200,
});
wiFirst = $("#contener").width();
hiFirst = $("#contener").height();
}
reader.readAsText(file);
});
我可以刪除/刪除緩存文件?它甚至被緩存在瀏覽器中?
它沒有被緩存,它只是選定的文件。您正在收聽更改事件。如果再次選擇相同的文件沒有任何變化,則不會觸發更改事件。閱讀完後你可以嘗試設置'e.target.files = null'或類似的東西。 (順便說一句,它與上傳無關,你沒有上傳任何東西,只是在本地加載它,對吧?) – Winchestro 2014-10-29 16:28:47
是的,我在本地加載它。 'e.target.files = null'沒有幫助。 – sko 2014-10-29 17:03:04