选择2 optgroup ajax json fomat
我想按选择2 optgroup ajax json fomat,json,ajax,laravel,jquery-select2,Json,Ajax,Laravel,Jquery Select2,我想按libelle对返回的json数据进行分组,结果如下 脚本: 输出: 是否有可能使小组在不重复诽谤词的情况下正常工作 JSON输出: [{"id":1,"libelle":"Laboratoire Arithm\u00e9tique calcul Scientifique et Applications","nom":"jhon","prenom":"M"},{"id":2,"libelle":"Laboratoire Arithm\u00e9tique calcul Scientifi
libelle
对返回的json数据进行分组,结果如下
脚本:
输出:
是否有可能使小组在不重复诽谤词的情况下正常工作
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个元素,选中此选项是否意味着:processResults:function(data){return{results:$.map(groupBy(data,'libelle')、function(item,key){var children=item;return{text:key,children:item.nom+''+item.prenom,}}};},我只获取optgroup数据,没有子对象显示它在返回语句之前的console.log项中记录了什么?(14)[{…},{…}、{…}、{…}、{…}、{…}、{…}、{…}、{…}、{…}、{…}、{…}、{…}、{…}]0:{id:1,名称:“jhon”,prenom:“M”,libelle:“Laboratoroire Arithmétique calculture Scientifique et Applications 2016-2019«FSO»在最后一个答案之后,我确实更改了结果:$.map(数据,函数(项,键){到结果:$.map(groupBy(数据,'libelle')),函数(项,键){现在工作正常了,谢谢sérgio Reis
[{"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"}]
// Add this somewhere before the ajax
var groupBy = function(xs, key) {
return xs.reduce(function(rv, x) {
(rv[x[key]] = rv[x[key]] || []).push(x);
return rv;
}, {});
};
processResults: function (data) {
return {
results: $.map(data, function (item,key) {
var children = [];
for(var k in item){
var childItem = item[k];
childItem.text = item[k].nom +' '+ item[k].prenom;
children.push(childItem);
}
return {
text: key,
children: children,
}
})
};