jQuery ReferenceError:在 datagrid.js 中嵌入 Fuelux 时未定义定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15703368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 15:37:57  来源:igfitidea点击:

ReferenceError: define is not defined while embedding fuelux in datagrid.js

javascriptjquerydatagridrequirejsfuelux

提问by Lasang

I wanted to add use http://exacttarget.github.com/fuelux/to build a datagrid. I wanted to add the library to use it. I did the following:

我想添加使用http://exacttarget.github.com/fuelux/来构建数据网格。我想添加库来使用它。我做了以下事情:

<link href="<spring:url value='/assets/css/fuelux.min.css' htmlEscape='true' />"      media="all" rel="stylesheet" type="text/css" />
<link href="<spring:url value='/assets/css/fuelux-responsive.min.css' htmlEscape='true' />" media="all" rel="stylesheet" type="text/css" />
<script src="<spring:url value='/assets/js/fuelux-datagrid.js' htmlEscape='true' />" type="text/javascript"></script>

I am sure that the path are correct because they work in other libraries. However, I get following error:

我确信路径是正确的,因为它们在其他库中工作。但是,我收到以下错误:

ReferenceError: define is not defined
[Break On This Error] 
define(['require','jquery'],function(require) {

where define(['require','jquery'],function(require) {...is code in fuelux-datagrid.js.

define(['require','jquery'],function(require) {...的代码在哪里fuelux-datagrid.js

  • What is this error?
  • I think defineis a keyword of require.js. Does this mean fuelux-datagridhas dependency on require.js?
  • Can anybody explain me how to load the library so to make it work?
  • 这是什么错误?
  • 我认为definerequire.js的关键字。这是否意味着Fuelux-datagrid依赖于require.js
  • 谁能解释我如何加载库以使其工作?

采纳答案by Adam Alexander

If you are not using RequireJS you can get around this by loading just the loader.min.js in a basic script tag:

如果你没有使用 RequireJS,你可以通过在基本脚本标签中加载 loader.min.js 来解决这个问题:

<script src="http://fuelcdn.com/fuelux/2.3/loader.min.js"></script>

This package contains all of the JavaScript needed for Bootstrap and Fuel UX, with no external dependency on an AMD loader.

该软件包包含 Bootstrap 和 Fuel UX 所需的所有 JavaScript,不依赖于 AMD 加载器。

回答by user1791567

This worked for me:

这对我有用:

<script src="https://raw.github.com/ExactTarget/fuelux/master/lib/require.js"></script>
<script type="text/javascript" src="https://raw.github.com/ExactTarget/fuelux/master/dist/datagrid.js"></script>

I tried what @AdamAlexander suggested and what is suggested hereand didn't work. I also tried the latest requiredjs and got a nasty exception. Go figure.

我尝试了@AdamAlexander 建议的内容和此处建议的内容,但没有奏效。我还尝试了最新的 requiredjs 并得到了一个令人讨厌的异常。去搞清楚。

回答by plalx

Yes, they seem to have a dependency on RequireJS. I must agree they don't have much resources that explains how to load the library (at least from what I saw), but what I would do is load require.js and check what other resources it is trying to load afterwards, by looking at the network requests.

是的,他们似乎依赖 RequireJS。我必须同意他们没有太多资源来解释如何加载库(至少从我所看到的),但我要做的是加载 require.js 并检查它之后尝试加载的其他资源,通过查看在网络请求。

Here's an example on how to setup RequireJS. You can also look at their docs.

这是一个关于如何设置 RequireJS 的示例。你也可以看看他们的文档

<script src="scripts/require.js"></script>
<script>
  require.config({
    baseUrl: "/another/path", //here's where it will look for scripts
    paths: {
        "some": "some/v1.0" //path to other dependencies not located in the base path
    }
  });
</script>