Select2 Dependent下拉列表 [英] Select2 Dependent dropdown lists

查看:113
本文介绍了Select2 Dependent下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Select2插件来拥有4个相互依赖的下拉列表。我一直在努力找到更新加载选项的数据的正确方法。

I am trying to use the Select2 plugin to have 4 dropdown lists that depend on each other. I have struggled to find the right way to update the data that loads the options in.

我的目标是通过ajax加载新数据,但是一旦我有了客户端我无法将新数据添加到选择列表。

My goal is to load the new data via ajax, but once I have it in the client I am unable to add the new data to the select list.

我尝试的代码在这里:

$(#"a3").select2({
    placeholder: "select an item",
    allowClear: true}).on("change",
    function (e) {
         var results = $.get("url?id=2",
            function (data, textStatus, jqXHR) {
                $(this).select2({ data: { results: data, text: "Name" } });
        });
    }
); 

此处还有另一个问题
select2动态更改项目
但解决方案适用于Select2 v3.2但不适用于Select2 v3.3

There is another question here select2 changing items dynamically but the solution there worked with Select2 v3.2 but not Select2 v3.3

推荐答案

Igor回来找我这样做

Igor has come back to me with a way to do this

var data=[...];    
$().select2({data: function() {return {results:data};}});    
/// later    
data=[...something else];    
// next query select2 will use 'something else' data

这篇关于Select2 Dependent下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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