[英]jquery select2 append selected item?
I'm trying to select an item from multi select jquery select2 with ajax 我正在尝试从使用ajax的多选择jquery select2中选择一个项目
HTML HTML
<select name="schools" id="schools" multiple='multiple'>
<option value="-1000">select all</option>
<option value="35102907">org1</option>
</select>
JS JS
$("#schools").select2({
ajax: {
url: "ajax_controller.php",
dataType: 'json',
data: function (params) {
return {
a: 'getSchoolList',
c: 'model_milk_contract',
p: [params.term],
cs: csrf
}
},
processResults: function (response) {
return {
results: $.map(response, function(obj) {
return { id: obj.org_code, text: obj.org_name };
})
}
}
}
}); });
but when one item selected, jquery says in console: 但是当选择一项时,jquery在控制台中说:
Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
未捕获的TypeError:无法在“节点”上执行“ appendChild”:参数1的类型不是“节点”。
then i tried to find the problem and after some time i found in below line of jquery core, ret[i]
must be a node object
, but what it gets is array of node objects
and if i pass ret[i][0]
to this function, it works! 然后我试图找到问题,一段时间后,我在jquery核心的下面一行中找到了,
ret[i]
必须是一个node object
,但是它得到的是array of node objects
如果我通过ret[i][0]
使用此功能,就可以了!
fragment.appendChild( ret[i] );
what's the problem?! 有什么问题?!
Finaly I found the problem: my jquery was too old and its version was 1.7.1 while select2 version 4 needs min jquery 1.8. 最后,我发现了问题:我的jquery太旧了,它的版本是1.7.1,而select2版本4需要min jquery 1.8。 thanks...
谢谢...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.