我正在使用Select2 Ajax远程选项获取数据:
$('#t').select2({
ajax: {
url: '../ajax/results.php',
data: function (params) {
return {
search: params.term,
page: params.page || 1
};
}
}
});
到目前为止,结果是这样返回的(请注意
<small>
标签):
{
"results": [
{
"id": "1",
"text": "Doe Joe, <small>Mr.</small>"
},
{
"id": "2",
"text": "Smith Anne, <small>Mrs.</small>"
},
{
"id": "3",
"text": "Rossi Mario, <small>Mr.</small>"
},
...
],
"pagination": {
"more": false
}
}
在
<select>
, the
<小>
标记按原样打印,而不是被解析。
选择2个文档
says that HTML are not rendered
默认情况下,呈现的结果必须包装在jquery对象中才能工作,但没有给出进一步的示例。
所有涉及的例子
templateResult
实际上,对于如何传递Ajax结果(即
https://select2.org/dropdown#templating
)
拜托,有什么帮助吗?