3 回答

TA貢獻1810條經(jīng)驗 獲得超4個贊
我還沒有看到人們真正回答的一種情況是,當選項來自AJAX時,如何進行預(yù)選擇,您可以選擇多個。由于這是AJAX預(yù)選擇的轉(zhuǎn)到頁面,因此我將在此處添加解決方案。
$('#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 關(guān)注
- 435 瀏覽
添加回答
舉報