2017-08-29 8 views
1

次のコードを使用してファイルダイアログを "projects"というフォルダに開くことはできますか? NW.JSアプリケーション?私はここにドキュメントを試してみました... https://github.com/nwjs/nw.js/wiki/file-dialogsが、私は、私は小さなバグ修正と、よりきれいな解決策を提案NW.JSでファイルダイアログを取得してアプリケーション内のフォルダに開く方法

<input id="fileDialog" type="file"> 
<script> 
document.querySelector('#fileDialog') 
    .addEventListener("change", function() { 
    var filePath = this.value; 
    alert(filePath); 
    }); 
</script> 

答えて

0
<label for="fileDialogOPEN"><img src="../images/open.png" style="width:20px;background:none;"></label> 
<div id="openBUT"></div> 

<script> 
var nwDir = process.cwd() + "/projects"; 
var goForIt = '<input id="fileDialogOPEN" nwworkingdir="' + nwDir + '" type="file" name="photo" style="display: none;" >'; 
    $("#openBUT").append(goForIt); 

    document.querySelector('#fileDialogOPEN') 
    .addEventListener("change", function() { 
    var filePath = this.value; 
    alert(filePath); 
    }); 
</script> 
0

を探しています何を発見していない:

<input id="opendlg" type="file" accept=".*" /> 

<script> 
opendlg.setAttribute('nwworkingdir', require('path').join(process.cwd(), 'projects')); 
opendlg.addEventListener('change', function (e) { 
    var filepath = e.target.value; 
    if (filepath) { 
    e.target.value = ''; // or you will not receive change-event next time on the same file 
    alert(filepath); 
    } 
}); 
</script>