web*_*ter 10 javascript requirejs twitter-bootstrap tether
Bootstrap的最新测试版(v4)使用Tether js来定位元素,我无法让它在我的Requirejs应用程序中运行.
在我的requirejs配置中,我有以下垫片
paths: {
jquery: '/path/to/jquery',
tether: '/path/to/tether'
},
shim: {
'bootstrap': ['tether', 'jquery']
}
Run Code Online (Sandbox Code Playgroud)
当我想在我的应用程序中激活工具提示时,我使用以下代码,我认为是正确的
function page_events() {
requirejs(['bootstrap'], function(bootstrap) {
$('[data-toggle="tooltip"]').tooltip();
});
}
Run Code Online (Sandbox Code Playgroud)
这应首先加载bootstraps依赖项,然后执行代码.所以通常应该在这段代码之前包含Tether.
但控制台的结果是
未捕获的ReferenceError:未定义系绳
有没有人有同样的问题?
创建一个这样的脚本:
define(['lib/tether.min'], function(tether) {
window.Tether = tether;
return tether;
});
Run Code Online (Sandbox Code Playgroud)
然后改变这个:
paths: {
jquery: '/path/to/jquery',
// tether: '/path/to/tether'
tether: '/path/to/your-own-tether'
},
shim: {
'bootstrap': ['tether', 'jquery']
}
Run Code Online (Sandbox Code Playgroud)
为什么?因为浏览器需要这个:
window.Tether = tether; // May be both requirejs and tether didn't do this
Run Code Online (Sandbox Code Playgroud)
如果您希望 Tether 在全球范围内可用,您应该使用脚本标签手动将其包含在内。RequireJS 不会公开它。
<script type="text/javascript" src="/js/tether.js"></script>
<script type="text/javascript" src="/js/optimized.min.js"></script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2932 次 |
| 最近记录: |