[問題] node.js太忙引起的前端問題
Hi 各位大大好 小魯最近用nw.js在寫讀取檔案的程式
我想呈現讀取的進度條,卻發現讀取檔案的時候程式太忙
完全不會理UI要做變化,可是javascript不是非同步執行的嗎?
完全不懂為什麼會出現這狀況
以下是我的程式範例,UI是使用bootstrap
for(var i=1; i<=days;i++){
d = y+'/'+m+'/'+add_zero(i);
file_path = f_path + '/' + y+'-'+ m +'-' + add_zero(i) + '_'.txt';
(function(file_path, d){
check_file(file_path , function(back){
if( back.status == 1){
load_file(file_path, function(data){
count++;
process_bar(0, days, count);
if(count > days ){
console.log(count);
}
});
}
});
})(file_path,d);
}
function process_bar(min, max, now){
$('#bar').attr('aria-valuemin', min);
$('#bar').attr('aria-valuemax', max);
$('#bar').attr('aria-valuenow', now);
$('#bar').attr('style', 'width:'+ Math.round( now/(min+max)*100 ) +'%');
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 219.87.162.226
※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1464589348.A.859.html
推
05/30 17:10, , 1F
05/30 17:10, 1F
→
05/30 17:11, , 2F
05/30 17:11, 2F
→
05/30 17:12, , 3F
05/30 17:12, 3F
→
05/30 17:46, , 4F
05/30 17:46, 4F
→
05/30 17:47, , 5F
05/30 17:47, 5F
→
05/30 17:47, , 6F
05/30 17:47, 6F
→
05/30 17:47, , 7F
05/30 17:47, 7F
→
05/30 17:49, , 8F
05/30 17:49, 8F
→
05/30 18:12, , 9F
05/30 18:12, 9F
→
05/30 19:36, , 10F
05/30 19:36, 10F
→
05/30 19:37, , 11F
05/30 19:37, 11F
→
05/31 10:35, , 12F
05/31 10:35, 12F
→
05/31 10:37, , 13F
05/31 10:37, 13F
→
05/31 10:37, , 14F
05/31 10:37, 14F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章