jQuery的选择2 - 不工作 [英] jquery select2 - not working

查看:159
本文介绍了jQuery的选择2 - 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的选择2插件(ivaynberg.github.io/select2)。我想显示一个下拉列表(选择)。这是凑data.php作为选项的所有项目。但是选择二,就是要自动完成插件,并应搜索的搜索项客户端输入,并且只显示匹配结果。目前,它显示的所有项目,并没有得到搜索结果。对不起,我的语言

I am using select2 plugin(ivaynberg.github.io/select2). I am trying to display a dropdown(select). It is getting all the items in data.php as options. However select2 is meant to be autocomplete plugin and should search for the search term a client input, and display the matching results only. At the moment it is displaying all the items and not getting the search results. Sorry for my language

data.php是呼应了这一点:

data.php is echoing out this:

[{
    "id": "1",
    "text": "item1",
    "exercise": "blah text"
  }, {
    "id": "2",
    "text": "item2"
  }
]

在code是:

The code is:

$(document).ready(function () {
    $('#thisid').select2({
        minimumInputLength: 2,
        ajax: {
            url: "data.php",
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term
                  };
            },
            results: function (data, page) {
                return {
                    results: data
                };
            }
        }
    });
});

和输入的是:

<input type="hidden" id="thisid" style="width:300px" class="input-xlarge" />

我想找到一个线索,我很新的这个插件,并花了一天在看的例子。

I want to find a clue, I am quite new to this plugin and have spent a day for looking at examples.

推荐答案

更新:此问题已修复在选择二4.0。从pre-发行说明:

select2 will not do AJAX if attached to a standard select form control. It MUST be attached to a hidden input control to load via AJAX.

Update: This has been fixed in Select2 4.0. From Pre-Release notes:

为所有的数据适配器标准元素,不再需要隐藏要素的一致性。

Consistency with standard elements for all data adapters, removing the need for hidden elements.

https://select2.github.io/announcements-4.0.html

有,也可以在其实施例部分见于功能。 https://select2.github.io/examples.html

It can also be seen in function in their examples section. https://select2.github.io/examples.html

这篇关于jQuery的选择2 - 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆