$(...)。jstree不是函数,在Electron js中使用JSTree

问题描述 投票:2回答:2

我正在使用pythondjangojQuery jsTree构建应用程序。该应用程序正在正常运行浏览器,但当我为我的项目创建电子应用程序时,它正在显示

$(...)。jstree不是一个函数。

我收到了这个错误

Uncaught Error: Cannot find module 'jquery'
    at Module._resolveFilename (module.js:485:15)
    at Function.Module._resolveFilename (/usr/local/lib/node_modules/electron/dist/resources/electron.asar/common/reset-search-paths.js:35:12)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at http://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/jstree.min.js:2:146
    at http://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/jstree.min.js:2:175

我还在jquery CDN链接之后包含了以下脚本。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script>
            try {
                $ = jQuery = module.exports;
            } catch(e) {}
        </script>
javascript jquery electron jstree
2个回答
1
投票

找到了答案

<!-- Insert this line above script imports  -->
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>

<!-- normal script imports etc  -->
<script src="scripts/jquery.min.js"></script>    
<script src="scripts/vendor.js"></script>    

<!-- Insert this line after script imports -->
<script>if (window.module) module = window.module;</script>

参考:Electron: jQuery is not defined


-2
投票

由此:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script>
            try {
                $ = jQuery = module.exports;
            } catch(e) {}
        </script>

改变这个:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
            <script>
                try {
                    $.jQuery = module.exports;
                } catch(e) {}
            </script>

你的功能错了。

你不能做$=jquery="something"。因此错误

© www.soinside.com 2019 - 2024. All rights reserved.