javascript - $(...).jstree 不是函数,在 Electron js 中使用 JSTree
问题描述
我正在python
django
使用jQuery
and构建一个应用程序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>
解决方案
找到了答案
<!-- 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>
推荐阅读
- laravel - Laravel 5 | File upload - If file exists add number to filename
- java - Many To Many collection always null (Spring Boot)
- typescript - Is there a way to have strong type check in React-Admin resources?
- r - How to put a part of result in R markdown
- javascript - Executing Python via Pyodide in Github Pages
- jasper-reports - Jaspersoft Studio error : Type mismatch : cannot convert from boolean to boolean
- python - Understanding custom policies in stable-baselines3
- macos - 在通常的方法都不起作用之后,我该如何修复我的自制软件?
- python - 每次我按多次鼠标按钮时,pygame 子弹都会重置
- python - 无法正确设置日期时间格式