3 回答
TA贡献1810条经验 获得超4个赞
我还没有看到人们真正回答的一种情况是,当选项来自AJAX时,如何进行预选择,您可以选择多个。由于这是AJAX预选择的转到页面,因此我将在此处添加解决方案。
$('#mySelect').select2({
ajax: {
url: endpoint,
dataType: 'json',
data: [
{ // Each of these gets processed by fnRenderResults.
id: usersId,
text: usersFullName,
full_name: usersFullName,
email: usersEmail,
image_url: usersImageUrl,
selected: true // Causes the selection to actually get selected.
}
],
processResults: function(data) {
return {
results: data.users,
pagination: {
more: data.next !== null
}
};
}
},
templateResult: fnRenderResults,
templateSelection: fnRenderSelection, // Renders the result with my own style
selectOnClose: true
});
- 3 回答
- 0 关注
- 406 浏览
添加回答
举报