如何在JQuery select2中添加自定义数据属性

时间:2018-10-17 02:46:18

标签: jquery jquery-select2

我正在通过ajax填充select2中的数据,并且将id和text传递为select2的要求,但是,我想在数据属性中添加一些值。这是我从php传递到ajax的数据。

{
id: 1,
ws_header_id: 45, 
ws_collection_header_id: 1,
text: "Some Texts", 
}

这是我的ajax:

 $.ajax({
                url: serverUrl,
                method: "GET",
                cache:false,
                data: bodyData,
                async: true,
                success: function (result) {

                    if(result){

                        console.log(result);
                        $(".working-schedule-id-select2").select2({data: result});

                    }
                },
                error: function (error) {
                    console.log(error.responseText);
                }
            });

我想将ws_header_id添加到<option>标签中的某些自定义data-ws-header-id属性中。

0 个答案:

没有答案
相关问题