How to reload jquery dropkick object

后端 未结 6 989
执念已碎
执念已碎 2021-02-08 16:39

Im using a simple select list and the jquery.dropkick library to make it beautiful. Now i want to change that dropkick content after the corresponding select element has been ch

6条回答
  •  难免孤独
    2021-02-08 17:12

    I leveraged Diode's answer to modify the Dropkick code to make this a little cleaner:

    // Reload the dropkick select widget after options have changed
    // usage: $("...").dropkick('reload');
    methods.reload = function () {
        var $select = $(this);
        var data = $select.data('dropkick');
        $select.removeData("dropkick");
        $("#dk_container_"+ data.id).remove();
        $select.dropkick(data.settings);
    };
    

    Add the above code right after the following snippet in dropkick.js:

    methods.reset = function () {
      ...
    };
    

    Then you can use it programatically:

        $('#my-select').html("");
        $('#my-select').dropkick('reload');
    

提交回复
热议问题