【发布时间】:2018-08-18 06:36:53
【问题描述】:
我想将返回的 json 数据按libelle 分组,我最终得到以下结果
脚本:
$('.membre').select2({
placeholder: 'Select an item',
ajax: {
url: '/select2-autocomplete-ajax',
dataType: 'json',
delay: 250,
data: function (params) {
return {
membre_id: params.term // search term
};
},
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.libelle,
children: [{
id: item.id,
text: item.nom +' '+ item.prenom
}]
}
})
};
},
cache: true
}
});
有没有可能在不重复libelle 的情况下使小组正常工作?
JSON 输出:
[{"id":1,"libelle":"Laboratoire Arithm\u00e9tique calcul Scientifique et Applications","nom":"jhon","prenom":"M"},{"id":2,"libelle":"Laboratoire Arithm\u00e9tique calcul Scientifique et Applications","nom":"JHON","prenom":"jhon"}]
【问题讨论】:
-
请从 json 输出中提供 2 或 3 个元素
标签: json ajax laravel jquery-select2