You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aggregation-platform/plugins/configs/ts/configsUtils.ts

51 lines
1.0 KiB

/// <reference path="../../includes.ts"/>
module Configs{
export function removeElementByValue(array:Array<any> ,value:any, key?:string ){
if(key){
for(var i=0; i<array.length; i++){
if(array[i][key] === value){
array.splice(i ,1);
break;
}
}
}else{
for(var i=0 ; i<array.length; i++){
if(array[i] === value){
array.splice(i ,1);
break;
}
}
}
}
export function removeElementsByValue(array: Array<any>, elements:Array<any>){
angular.forEach(elements, (element) =>{
removeElementByValue(array, element.value, element.key);
});
}
/**
对象的深拷贝
*/
export function deepCopy(object) {
var n,i;
if (object instanceof Array) {
n = [];
for (i = 0; i < object.length; ++i) {
n[i] = deepCopy(object[i]);
}
return n;
} else if (object instanceof Object) {
n = {}
for (i in object) {
n[i] = deepCopy(object[i]);
}
return n;
} else {
return object;
}
}
}