使用ajax加载下拉值后,Yii2 kartik相关下拉列表未使用ajax更改所选值

时间:2017-01-27 08:31:30

标签: php jquery ajax yii2 kartik-v

想要更改相关下拉列表的选定值。在代码不起作用的情况下,在依赖下拉列表中使用ajax加载下拉值后

$("#dependentDropDownID").select2("val", data);

以上代码在首次加载相关下拉列表时工作正常。

2 个答案:

答案 0 :(得分:3)

当我们使用kartik select2下拉时,下拉的实际ID在隐藏状态下消失,因此要更改隐藏下拉值,我们必须在该id上使用“更改”事件。使用以下代码更改下拉列表的选定值。

$("#dependentDropDownID").val(data).change();

答案 1 :(得分:0)

Kartik准备了名为DepDrop的插件,它将为您完成所有工作。

    [
    {
        "id": 3,
        "name": "Challenge Modes",
        "frozen": true,
        "encounters": [
            {
                "id": 11182,
                "name": "Auchindoun"
            },
            {
                "id": 11175,
                "name": "Bloodmaul Slag Mines"
            },
            {
                "id": 11279,
                "name": "The Everbloom"
            },
            {
                "id": 11208,
                "name": "Grimrail Depot"
            },
            {
                "id": 11195,
                "name": "Iron Docks"
            },
            {
                "id": 11176,
                "name": "Shadowmoon Burial Grounds"
            },
            {
                "id": 11209,
                "name": "Skyreach"
            },
            {
                "id": 11358,
                "name": "Upper Blackrock Spire"
            }
        ],
        "brackets": [
            {
                "id": 1,
                "name": "6.0"
            },
            {
                "id": 2,
                "name": "6.1"
            },
            {
                "id": 3,
                "name": "6.2"
            }
        ]
    },
    {
        "id": 4,
        "name": "Throne of Thunder",
        "frozen": true,
        "encounters": [
            {
                "id": 1577,
                "name": "Jin'rokh the Breaker"
            },
            {
                "id": 1575,
                "name": "Horridon"
            },
            {
                "id": 1570,
                "name": "Council of Elders"
            },
            {
                "id": 1565,
                "name": "Tortos"
            },
            {
                "id": 1578,
                "name": "Megaera"
            },
            {
                "id": 1573,
                "name": "Ji-kun"
            },
            {
                "id": 1572,
                "name": "Durumu the Forgotten"
            },
            {
                "id": 1574,
                "name": "Primordius"
            },
            {
                "id": 1576,
                "name": "Dark Animus"
            },
            {
                "id": 1559,
                "name": "Iron Qon"
            },
            {
                "id": 1560,
                "name": "Twin Consorts"
            },
            {
                "id": 1579,
                "name": "Lei Shen"
            },
            {
                "id": 1580,
                "name": "Ra-den"
            }
        ]
    },

插件:Kartik DepDrop