gpt4 book ai didi

jquery select2刷新数据

转载 作者:行者123 更新时间:2023-12-03 22:29:58 28 4
gpt4 key购买 nike

我使用select2进行选择并使用ajax加载数据,当初始选择后状态发生变化时,如何替换旧数据。

我的加载代码:

$('.datetimepicker').on("changeDate", function() {  
//refresh selectbox ??
doctor_id = $(".select2-doctors").val();
clinic_id = $(".select2-clinics").val();
date = $('.datetimepicker').datepicker('getFormattedDate');
$.ajax({
url: '/admin/appointments/time_slots',
type: 'GET',
dataType: 'json',
data: {doctor_id: doctor_id, clinic_id: clinic_id, date: date}
})
.done(function(data) {
console.log("success");
console.log(data);
$('.select2-slot').select2({
data: data.slots
});
})
.always(function() {
console.log("complete");
});
});

最佳答案

尝试在更新数据之前清空 select2 选项,这是因为默认情况下它将数据附加到现有选项。

$('.select2-slot').empty();
$('.select2-slot').select2({
data: data.slots
});

关于jquery select2刷新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34962269/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com