日照项目的居民端小程序
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.

45 lines
1012 B

import $ from 'jquery';
/*
---------------------------------------------------------------*/
/**
* 扩展对象或数组返回新的对象(深层次克隆)
*/
export function objExtend(...obj) {
return $.extend(true, {}, ...obj);
}
/**
* 对象坍塌返回新的对象不会改变原有对象
* 示例
* ({a:{name:'a', val:1}, b:{name:'b', val:2}}, 'val') => {a:1, b:2}
*/
export function objCollapse(obj, subKey = 'value') {
obj = objExtend(obj);
for (let key in obj) {
let item = obj[key];
if (typeof item == 'object' && typeof item[subKey] != undefined) {
obj[key] = item[subKey];
}
}
return obj;
}
/**
* 对象中是否有某个值
*/
export function objHasValue(obj, v) {
return Object.values(obj).some(function (item) {
return v == item;
});
}
/**
* 对象中是否有某个键
*/
export function objHasKey(obj, key) {
return Object.keys(obj).some(function (item) {
return key == item;
});
}