【发布时间】:2017-01-26 11:56:32
【问题描述】:
当使用 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)
【问题讨论】:
-
请发布您的选择元素的 html 和用于初始化 select2 插件的 js 代码。
-
我创建了一个小提琴,但我无法重现您的问题。 Chrome 中没有错误:jsfiddle.net/01zb15mq.
-
当我尝试使用不同的标签更新我的 select2 时,我想我遇到了同样的问题。我已经从 Firefox 和 chrome 中检查了这一点。两者都抛出错误:# chrome Version 56.0.2924.87
Uncaught TypeError: Cannot read property 'current' of null# firefox 51.0.1TypeError: b.dataAdapter is nulljsfiddle 可从:jsfiddle.net/PBrockmann/74v2gzhe -
你能加载未缩小的库并查看是否可以获得更多错误上下文吗?您正在加载缩小的“select2.full.min.js:2”。
-
你有没有想过这个问题?
标签: javascript jquery jquery-select2