我有一个这样的数组:
0: {ClusterId: "10.210.28.231", Device IP: "10.210.28.231", SlotID: "1"}
1: {ClusterId: "10.210.28.234", Device IP: "10.210.28.234", SlotID: "1"}
2: {ClusterId: "10.210.28.231", Device IP: "10.210.28.231", SlotID: "2"}
3: {ClusterId: "10.210.28.234", Device IP: "10.210.28.234", SlotID: "2"}
4: {ClusterId: "10.210.28.234", Device IP: "10.210.28.234", SlotID: "2"}
5: {ClusterId: "10.210.28.231", Device IP: "10.210.28.231", SlotID: "2"}
我正在尝试通过ClusterId和删除重复项SlotID。下面是我的示例代码,其中我将重复值推送到一个数组 ( duplicateArrayVal) 并将非重复值推送到另一个数组 ( importArrayVal)
UniqueArraybyObject($scope.excelRowArray, "SlotID", "ClusterId");
function UniqueArraybyObject(collection, slotId, clusterName) {
var importArrayVal = [],
slot = [],
clusters = [];
$scope.duplicateArrayVal = [];
angular.forEach(collection, function(item) {
var tempSlot = item[slotId];
var cluster = item[clusterName];
if ((slot.indexOf(tempSlot) === -1) || (clusters.indexOf(cluster) === -1)) {
slot.push(tempSlot);
clusters.push(cluster);
importArrayVal.push(item);
} else {
$scope.duplicateArrayVal.push(item);
}
});
return importArrayVal;
};
发生在我身上的问题是第 3,4 和 5 行的项目没有显示,因为它们被视为重复项。但只有第 4 行和第 5 行是重复的,而不是第 3 行。我需要第三行在非重复数组中。
请帮助我实现这一目标
相关分类