gpt4 book ai didi

javascript - jquery select2 : TypeError: b. 数据适配器为空

转载 作者:数据小太阳 更新时间:2023-10-29 06:10:03 25 4
gpt4 key购买 nike

当使用 select2 多选并选择一个选项时,我收到此错误消息:

TypeError: b.dataAdapter is null

有人知道这是怎么回事吗?

多选工作正常,我只是想知道这条消息。

编辑:

这是我的 html:

<div class="form-group">
<label class="control-label col-md-12" for="participant-id">Participant
<span class="required"> * </span>
</label>
<div class="col-md-12">
<input type="hidden" name="participant_id" value=""/>
<select name="participant_id[]" multiple="multiple" class="form-control select2me participantSelector" required="required" id="participant-id">
<option value=""></option>
</select>
</div>
</div>

这是 jquery 初始化:

$(".select2me").select2({
placeholder:"Select",
width:"auto",
allowClear:!0
});

如果在另一个下拉列表“projectSelector”中选择了一个值,我得到的多选数据:

$('.projectSelector').on('change', function() {
var targetProject_id = $('#project-id :selected').val();
updateParticpantDropdown(targetProject_id);
});


function updateParticpantDropdown(selectedProjectId){
$.ajax({
type: "POST",
url: '/xx/projects/xx/'+ selectedProjectId,
dataType : "json",
success: function (response, status) {
if (response.result == "success"){
var data = response.data;
$(".participantSelector").empty().select2({
placeholder: "Click here to select participants",
allowClear: false,
data: data
});
}
}
});
}

数据正在加载到多选中,一切都按预期在屏幕上工作。就在控制台中,我收到错误消息

TypeError: b.dataAdapter is null

这是我的 json 响应(简而言之):

{
"result":"success",
"data":[
{"id":18,"text":"xx, Ana Rosa"},
{"id":17,"text":"xx, Saul"},
{"id":14,"text":"xx, Jesus"},
{"id":15,"text":"xx, Jose Sergio"},
{"id":13,"text":"xx, Guadalupe"},
{"id":12,"text":"xx, Adolfo"},
{"id":25,"text":"xx, Roland"},
{"id":16,"text":"xx, Mariela Elisa"},
{"id":11,"text":"xx, Roberto Carlos "},
{"id":19,"text":"xx, Jose Rafael"},
{"id":2,"text":"xx, Juan Carlos"}
]
}

在 Chrome 中我收到这条消息:

select2.full.min.js:2 
Uncaught TypeError: Cannot read property 'current' of null
at HTMLSelectElement.<anonymous> (select2.full.min.js:2)
at HTMLSelectElement.dispatch (jquery.min.js:3)
at HTMLSelectElement.r.handle (jquery.min.js:3)
at Object.trigger (jquery.min.js:3)
at HTMLSelectElement.<anonymous> (jquery.min.js:3)
at Function.each (jquery.min.js:2)
at n.fn.init.each (jquery.min.js:2)
at n.fn.init.trigger (jquery.min.js:3)
at d.select (select2.full.min.js:1)
at d.select (select2.full.min.js:2)

最佳答案

由于 selector2 元素倾向于存储一些额外的数据,我注意到除了 $(".participantSelector").empty() 之外,当列表元素的数据被清除时,错误是走了。所以,试试这个方法:

var selector = $(".participantSelector");
selector.empty();
selector.removeData();
selector.select2({
placeholder: "Click here to select participants",
allowClear: false,
data: data
});

希望它也对您有用。

关于javascript - jquery select2 : TypeError: b. 数据适配器为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41872930/

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