Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 原子/电子动态HTML路径_Javascript_File_Templates_Electron - Fatal编程技术网

Javascript 原子/电子动态HTML路径

Javascript 原子/电子动态HTML路径,javascript,file,templates,electron,Javascript,File,Templates,Electron,我对Electron非常陌生,所以这可能是一个愚蠢的问题,然而:我的应用程序使用多个窗口,所以我自然想实现一个(非常)基本的模板引擎,以避免在每个页面上重新创建页面的页眉和页脚。所以我这样做了: function setWindowContent(template) { FileSystem.readFile(path.resolve(__dirname, 'layout.html'), 'utf-8', function(error, layoutCode){ if (

我对Electron非常陌生,所以这可能是一个愚蠢的问题,然而:我的应用程序使用多个窗口,所以我自然想实现一个(非常)基本的模板引擎,以避免在每个页面上重新创建页面的页眉和页脚。所以我这样做了:

function setWindowContent(template)
{
    FileSystem.readFile(path.resolve(__dirname, 'layout.html'), 'utf-8', function(error, layoutCode){
        if (!error) {
            FileSystem.readFile(path.resolve(__dirname, template+'.html'), 'utf-8', function(error, content){
                if (!error){
                    content = layoutCode.replace('{{main_content}}', content);

                    mainWindow.webContents.loadURL('data:text/html,' + content);
                }
            });
        }
    });
}
它可以工作,但是由于某些原因,我不能包含任何css或js文件,它就是找不到它们。“require”语句可以工作,但由于范围的原因,路径相当长。所以这是可行的:

<script>window.$ = window.jQuery = require('./../../../../../../js/jquery-2.2.1.min.js');</script>

我没有列出“node_modules”文件夹的内容,因为它需要几页,因为它是通过npm安装在本地安装的。

你能发布你的结构文件夹吗?请尝试不带点的路径
/css/style.css
如果不带点,将从根路径包含,这可能是您试图做的吗
/css/style.css
带点指的是当前目录,这就是为什么如果嵌套过多,则必须包含较长路径的原因。@Chrissi:尝试了带点和不带点的方法,但仍然无法使用:(
href=“./css/style.css”
这应该可以工作,您的控制台中有错误吗?@John The./css/style.css只有在我在浏览器窗口上调用loadURL时才能工作,例如mainWindow.loadURL('file://'+\uu dirname+'/layout.html');但我使用的是mainWindow.webContents.loadURL('data:text/html'+content);将两个文件组合在一起。它确实会按应有的方式显示模板,但路径不起作用。您可以发布您的结构文件夹吗?尝试不带点的路径吗?
/css/style.css
不带点的路径将包括根路径中的内容,这可能是您尝试执行的操作吗?
/css/style.css
带点指current目录,这就是为什么如果嵌套较多,则必须包含较长路径的原因。@Chrissi:尝试使用前面的点和不使用前面的点,但仍然无法使用:(
href=“./css/style.css”
这应该可以工作,您的控制台中有错误吗?@John The./css/style.css只有在我在浏览器窗口上调用loadURL时才能工作,例如mainWindow.loadURL('file://'+\uu dirname+'/layout.html');但我使用的是mainWindow.webContents.loadURL('data:text/html'+content);将两个文件组合在一起。它确实会按应有的方式显示模板,但路径不起作用。
<link href="./css/style.css" rel='stylesheet' type='text/css' />
<link href="./../../../../../../css/style.css" rel='stylesheet' type='text/css' />
├── css/
│   └── style.css
├── js/
├── node_modules/
├── main.js
├── package.json
├── layout.html
├── index.html