Programmatic selection of select2 which retrieves its data via Ajax

后端 未结 4 1713
野趣味
野趣味 2021-02-19 10:16

I am using select2 version 4.0, and I am trying to make a programmatic selection to a select box which gets its data from an ajax call.

In the documentation, I found how

4条回答
  •  闹比i
    闹比i (楼主)
    2021-02-19 11:08

    You can try this.

        var dataString = 'id='+$value;
        var promise = sendAjaxFunction('load_form.php?k=1',dataString);
        $("#LoadMachine").html("");
        promise.success(function (data) {
            $("#LoadMachine").html(data);
            $("#MachineName").select2({
                placeholder: 'Select Operation Name ...',
                allowClear: true
            });
            return false;
        });
    

    Load the data in a Div #LoadMachine and in result you can load select2.

提交回复
热议问题