简体   繁体   English

使用Select2获取错误 - “错误:没有select2 / compat / query”

[英]Using Select2 get error - “Error: No select2/compat/query”

I am attempting to use the Select2 library in my site to leverage placecomplete ( following it's rather simple configuration steps here ), but when I run the code I get a strange error - 我试图在我的网站中使用Select2库来利用placecomplete遵循这里相当简单的配置步骤 ),但是当我运行代码时,我得到一个奇怪的错误 -

Error: No select2/compat/query` 错误:没有select2 / compat / query`

I've tried googling it and it really seems like no one else has encountered this? 我试过谷歌搜索它,似乎没有其他人遇到过这个?

My code in a nutshell is, 我的代码简而言之,是

loading the files... 加载文件...

<link href="scripts/Select2/dist/css/select2.min.css" rel="stylesheet" />
<script src="scripts/Select2/dist/js/select2.min.js"></script>
<script src="scripts/jquery.placecomplete.js">//<![CDATA[//]]></script>

Tagging an input element in my body... 标记我体内的输入元素......

<input id="example123" class="example123" type="text" />

In my document.ready function, calling the following code... 在我的document.ready函数中,调用以下代码...

$('#example123').placecomplete({});

and thats where it throws the error. 这就是它抛出错误的地方。

Any ideas where Im going wrong, and what this error means? 我出错的任何想法,这个错误意味着什么?

You are running into two issues here, both of which can easily be fixed. 您在这里遇到两个问题,这两个问题都很容易修复。

  1. Select2 4.0.0 no longer supports the query option in the slimmed down, standard build. Select2 4.0.0不再支持精简版标准版本中的query选项。 This must be included in the full build ( select2.full.js ) as it is handled through a backwards compatibility module. 这必须包含在完整版本( select2.full.js )中,因为它是通过向后兼容性模块处理的。

  2. You are using Placecomplete and it depends on an older version of Select2. 您正在使用Placecomplete,它取决于旧版本的Select2。 It looks like Select2 3.5.2+ can work, but I can tell from the options that it is using, it cannot work with Select2 4.0.0. 它看起来像Select2 3.5.2+可以工作,但我可以从它使用的选项告诉它,它不能用于Select2 4.0.0。 There is an open ticket about this for Placecomplete. Placecomplete有关于此的公开票

当你的网页上有两个具有相同Id的控件时,我已经有了这个 - 我有一个隐藏的控件和一个选择(隐藏的控件是第一个)。

对我来说,将<input />标签更改为<select>标签有效。

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

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