初始化 Select2 抛出 define is not defined 错误

Initializing Select2 throws define is not defined error

当我下载 Select2 的 4.0.1 Release Candidate (https://github.com/select2/select2/releases/tag/4.0.1-rc.1) 并使用它时,出现 JavaScript 错误:Uncaught ReferenceError: define is not defined.

在这里我读到它与 AMD 加载器(我不使用)有关:https://groups.google.com/forum/#!topic/select2/PCQpiJxIIXQ

当我不使用 RC 的 jquery.select2.js,而是使用当前 master 的 select2.min.js 时:https://raw.githubusercontent.com/select2/select2/master/dist/js/select2.min.js

有效!

但我很好奇我在这里忽略了什么。很可能是我自己做错了什么。

编辑 - 代码示例:

在头部:

<script language='Javascript' src='scripts/jquery-1.9.1.min.js'></script>
<script language='Javascript' src='scripts/jquery.select2.js'></script>

正文中:

<script type="text/javascript"> 

    $(document).ready(function(){       

    $('#id_of_select').select2({
      tags: "true",
      placeholder: "",
      allowClear: true,
      tokenSeparators: [',', ' ']
    });
});
</script>

<select multiple id="id_of_select" name="name[]">
    <option value="1" selected="">Option 1</option>
    <option value="2" selected="">Option 2</option>
    <option value="5">Option 3</option>
</select>

好吧,我的错是..在 select2 包的文件夹结构中有几个文件夹,包括:

  • dist
  • src

我使用了 src 文件夹中的 javascript.. 但似乎正确的文件在 dist 文件夹中。