jquery select2 追加所选项目?
jquery select2 append selected item?
我正在尝试 select 来自多个 select jquery select2 和 ajax
的项目
HTML
<select name="schools" id="schools" multiple='multiple'>
<option value="-1000">select all</option>
<option value="35102907">org1</option>
</select>
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 };
})
}
}
}
});
但是当 selected 一个项目时,jquery 在控制台中说:
Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
然后我试图找到问题,一段时间后我在 jquery 核心的下面一行发现,ret[i]
必须是 node object
,但它得到的是 array of node objects
如果我将 ret[i][0]
传递给此函数,它就可以工作!
fragment.appendChild( ret[i] );
有什么问题吗?!
终于找到问题所在了:
我的 jquery 太旧了,它的版本是 1.7.1,而 select2 版本 4 需要最小 jquery 1.8。
谢谢...
我正在尝试 select 来自多个 select jquery select2 和 ajax
的项目HTML
<select name="schools" id="schools" multiple='multiple'>
<option value="-1000">select all</option>
<option value="35102907">org1</option>
</select>
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 };
})
}
}
}
});
但是当 selected 一个项目时,jquery 在控制台中说:
Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
然后我试图找到问题,一段时间后我在 jquery 核心的下面一行发现,ret[i]
必须是 node object
,但它得到的是 array of node objects
如果我将 ret[i][0]
传递给此函数,它就可以工作!
fragment.appendChild( ret[i] );
有什么问题吗?!
终于找到问题所在了: 我的 jquery 太旧了,它的版本是 1.7.1,而 select2 版本 4 需要最小 jquery 1.8。 谢谢...