简体   繁体   English

初始化Select2 throws定义未定义错误

[英]Initializing Select2 throws define is not defined error

When I download the 4.0.1 Release Candidate ( https://github.com/select2/select2/releases/tag/4.0.1-rc.1 ) of Select2 and use it, I get a JavaScript error: Uncaught ReferenceError: define is not defined . 当我下载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

Here I read that it has to do with the AMD loader (which I don't use): https://groups.google.com/forum/#!topic/select2/PCQpiJxIIXQ 在这里我读到它与AMD加载器(我不使用)有关: https//groups.google.com/forum/#!topic / select2 / PCQpiJxIIXQ

When I don't use the jquery.select2.js from the RC, but the select2.min.js from the current master: https://raw.githubusercontent.com/select2/select2/master/dist/js/select2.min.js 当我不使用来自RC的jquery.select2.js,而是来自当前主服务器的select2.min.js时: https ://raw.githubusercontent.com/select2/select2/master/dist/js/select2 。 min.js

it works! 有用!

But I'm curious what I overlook here. 但我很好奇我在这里忽略了什么。 Most likely I'm doing something wrong myself. 我很可能自己做错了什么。

Edit - code example: 编辑 - 代码示例:

in the head: 在脑袋里:

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

in the body: 在身体里:

<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>

Ok, my bad it is.. in the folder structure of the select2 package there are several folders including: 好吧,我的不好是..在select2包的文件夹结构中有几个文件夹,包括:

  • dist
  • src

I used the javascript from the src folder.. But it seems the right files are in the dist folder. 我使用了src文件夹中的javascript ..但似乎正确的文件位于dist文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM