我有一个包含组成员(last_name,first_name)的数组,但是在组“ Testgroup”中是另一个组“ Testgroup2”。不好的是,我没有从两个组中获得唯一的值。
有人可以帮忙吗?它的JavaScript
var manager_list = new Array;
var manager_list = new Array;
var srvData = new spl_srv();
<LIST PREFIX=list WHERE="group.last_name = 'Testgroup'">
var wc = "group = U'$list.member'";
var data = srvData.read("grpmem", wc, "member.last_name|member.first_name|member");
var anz = srvData.getcount();
if(anz > 0) {
for (i=0; i<anz; i++){
var UU_ID = srvData.getdata(i,2);
UU_ID = UU_ID.replace(/\r?\n|\r/g,"");
manager_list.push(srvData.getdata(i,0)+', '+srvData.getdata(i,1)+'@,@'+UU_ID);
}
}
else {
manager_list.push("$list.member.last_name, $list.member.first_name@,@$list.member");
}
最佳答案
有多种方法从数组中获取唯一值(删除重复项)var uniqueManagers = []; $.each(manager_list, function(i, el){ if($.inArray(el, uniqueManagers) === -1) uniqueManagers.push(el); });
let uniqueManagers = Array.from(new Set(manager_list))
您的代码应如下所示
var manager_list = new Array;
var manager_list = new Array;
var srvData = new spl_srv();
<LIST PREFIX=list WHERE="group.last_name = 'Testgroup'">
var wc = "group = U'$list.member'";
var data = srvData.read("grpmem", wc, "member.last_name|member.first_name|member");
var anz = srvData.getcount();
if(anz > 0) {
for (i=0; i<anz; i++){
var UU_ID = srvData.getdata(i,2);
UU_ID = UU_ID.replace(/\r?\n|\r/g,"");
manager_list.push(srvData.getdata(i,0)+', '+srvData.getdata(i,1)+'@,@'+UU_ID);
}
}
else {
manager_list.push("$list.member.last_name, $list.member.first_name@,@$list.member");
}
manager_list = Array.from(new Set(manager_list))