带有requireJS的工具提示系绳 [英] Tooltip Tether with requireJS

查看:89
本文介绍了带有requireJS的工具提示系绳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bootstrap的最新测试版(v4)使用Tether js来定位元素,我无法让它在我的Requirejs应用程序中运行。

latest beta version (v4) of Bootstrap uses Tether js to position elements, I am unable to let it work in my Requirejs app.

在我的requirejs配置中有以下垫片

in my requirejs config I have the following shim's

paths: {
    jquery: '/path/to/jquery',
    tether: '/path/to/tether'
},
shim: { 
     'bootstrap': ['tether', 'jquery']       
}

当我想在我的应用程序中激活工具提示时,我使用以下代码,我认为是正确的

And when I want to activate tooltips in my app, I use the following code which I think is correct

function page_events() {
    requirejs(['bootstrap'], function(bootstrap) {
        $('[data-toggle="tooltip"]').tooltip(); 
    }); 
}

这应首先加载bootstraps依赖项,然后再执行代码。所以通常应该在这段代码之前包含Tether。

This should load bootstraps dependencies first and afterwards execute the code. So normally Tether should be included before this piece of code.

但是控制台结果是


Uncaught ReferenceError:Tether未定义

Uncaught ReferenceError: Tether is not defined

有没有人遇到同样的问题?

Does anyone have the same issue?

推荐答案

创建一个这样的脚本:

define(['lib/tether.min'], function(tether) {
    window.Tether = tether;
    return tether;
});

然后改变这个:

paths: {
    jquery: '/path/to/jquery',
    // tether: '/path/to/tether'
    tether: '/path/to/your-own-tether'
},
shim: { 
     'bootstrap': ['tether', 'jquery']       
}

为什么?因为浏览器需要这个:

Why? because the browser need this:

window.Tether = tether; // May be both requirejs and tether didn't do this

这篇关于带有requireJS的工具提示系绳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆