[英]How do I use bootstrap slider in Electron?
I am getting the following error when I use bootstrap slider ( https://github.com/seiyria/bootstrap-slider ) in my Electron( http://electron.atom.io/docs/latest/tutorial/quick-start/ ) app : 当我在Electron( http://electron.atom.io/docs/latest/tutorial/quick-start/ )中使用引导程序滑块( https://github.com/seiyria/bootstrap-slider )时,出现以下错误)应用:
"Uncaught TypeError: $(...).Slider is not a function" “未捕获的TypeError:$(...)。滑块不是函数”
Earlier I was also struggling with using Jquery but solved it using : https://github.com/atom/electron/issues/254 : 早些时候我也在努力使用Jquery,但使用以下方法解决了它: https : //github.com/atom/electron/issues/254 :
window.$ = window.jQuery = require('/path/to/jquery'); window。$ = window.jQuery = require('/ path / to / jquery'); instead of regular :
而不是常规的:
The reason quoted was Query contains something along this lines: 引用的原因是查询包含以下内容:
if ( typeof module === "object" && typeof module.exports === "object" ) {
// set jQuery in `module`
} else {
// set jQuery in `window`
}
I don't understand what is the right way to use it for bootstrap the slider. 我不知道使用它引导滑块的正确方法是什么。
I could see that bootstrap-slider.js has a component dealing with "module" which might be causing the anomaly just like in jquery. 我可以看到bootstrap-slider.js包含一个处理“模块”的组件,这可能会导致异常,就像在jquery中一样。
(function(root, factory) {
if(typeof define === "function" && define.amd) {
define(["jquery"], factory);
} else if(typeof module === "object" && module.exports) {
var jQuery;
try {
jQuery = require("jquery");
} catch (err) {
jQuery = null;
}
module.exports = factory(jQuery);
} else {
root.Slider = factory(root.jQuery);
}
Please tell me how to deal with this. 请告诉我如何处理。
You have 2 options: 您有2个选择:
<script src="bower_components/jquery/dist/jquery.js"></script> <script type="application/javascript"> if (typeof module === 'object' && typeof module.exports !== 'undefined') { window.$ = window.jQuery = module.exports; } </script> <script src="path/to/bootstrap-slider.js"></script> <script type="application/javascript"> if (typeof module === 'object' && typeof module.exports !== 'undefined') { window.Slider = module.exports; } </script>
require
to include jQuery and Slider whenever you need them require
使用require
包括jQuery和Slider var $ = require('jquery'); var Slider = require('bootstrap-slider');
Found that solution below yesterday. 昨天在下面找到了该解决方案。 Worked for me both with jQuery and Bootstrap Slider.
为我使用jQuery和Bootstrap Slider。 Credits on the bottom.
在底部的学分。
A better an more generic solution IMO: 更好,更通用的解决方案IMO:
<!-- 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>
Benefits 优点
I was able to fix this by placing my path to jquery in the bootstrap-slider.js 我可以通过将我的 jquery路径放在bootstrap-slider.js中来解决此问题
Line 41: jQuery = require("my/path/to/jquery-2.1.4.min.js");
This is probably the wrong solution, but hopefully a bad idea can lead to a good one :) 这可能是错误的解决方案,但希望一个坏主意可以带来一个好主意:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.