【问题标题】:Difficulty loading xstyle as a dojo dependency难以将 xstyle 作为 dojo 依赖项加载
【发布时间】:2016-07-20 22:37:19
【问题描述】:

我正在尝试使用 Dojo 创建一个简单的自定义小部件,并希望使用 xstyle 加载 CSS。看着the reference in github,它说我可以添加

<script src="dojo/dojo.js" data-dojo-config="async: true, deps:['xstyle/main']"></script>

然后完成。问题是我需要在我的 dojo 模块下已经有 xstyle,我不确定从哪里获取/安装它?

总之,我有这个:

<script type="text/javascript">
        var dojoConfig = {
                async: true,
                parseOnLoad: true,
                packages: [
                    {
                        name: "app",
                        location: location.pathname.replace(/\/[^/]+$/, "") + "/app"
                    }
                ],
                deps: ['xstyle/main']
            };
</script>
<script type="text/javascript" src="app/js/dojo/dojo.js"></script>

我得到了错误Cannot find .../app/js/xstyle/main.js,这是有道理的,因为我没有它,而且我不知道从哪里得到它。

我从网站下载了 dojo 安装,其中包括 dojo、dijit、dojox 和主题。 CDN 似乎也没有 xstyle。我也尝试过 kriszyp 的其他方法:

<script src="xstyle/xstyle.js"></script> <!-- or use the minified xstyle.min.js -->

无济于事。我相信我会收到一些 already definednot defined 错误,具体取决于我是在道场声明之前还是之后添加它。

如果您能指出正确的方向,请告诉我!

【问题讨论】:

    标签: javascript dojo amd


    【解决方案1】:

    所以在仔细研究了这个问题后,我发现了this 的博客文章,它使用bower 来安装xstyle。在使用 bower (bower install xstyle) 安装后,我能够链接到 dojo 配置中的 xstyle 包:

    var dojoConfig = {
        async: true,
        parseOnLoad: true,
        packages: [
            {
                name: "app",
                location: location.pathname.replace(/\/[^/]+$/, "") + "/app"
            },
            {
                name: "xstyle",
                location: location.pathname.replace(/\/[^/]+$/, "") + "/app/bower_components/xstyle"
            },
       ]
    };
    

    这行得通,我可以使用'xstyle/css!./css/checkboxTree.css' 成功地将 CSS 加载到我的小部件中。我不确定这是否是最好的方法,但它确实有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      • 2014-06-16
      • 2018-05-24
      • 2020-07-21
      相关资源
      最近更新 更多