【发布时间】:2016-04-26 23:39:46
【问题描述】:
我正在尝试使用 electronjs 创建一个简单的桌面应用程序。我的目标是打开ShowOpenDialog,但由于(我的原因不明)它什么也没有打开。
树视图:
sample app
|-index.html
|-js
|--jquery.js
|--index.js
|-main.js
|-package.json
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<br />
<button id="openFile">Open</button>
<script>
window.$ = window.jQuery = require('./js/jquery.js');
</script>
<sctipt src ="./js/index.js"></sctipt>
</html>
index.js
$(document).ready(function() {
$("#openFile").click(function(){
dialog.showOpenDialog(function (fileNames) {
});
})
})
main.js
'use strict';
const electron = require('electron');
const dialog = require('electron').dialog;
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
let mainWindow;
function createWindow () {
mainWindow = new BrowserWindow({width: 800, height: 600});
mainWindow.loadURL('file://' + __dirname + '/index.html');
mainWindow.
mainWindow.on('closed', function() {
mainWindow = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
还有 package.json
{
"name": "electron-quick-start",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
"scripts": {
"start": "electron main.js"
}
}
【问题讨论】:
标签: javascript jquery electron