57 lines
2.1 KiB
JavaScript
57 lines
2.1 KiB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
export var isChecked = function isChecked(selectedKeys, eventKey) {
|
|
return selectedKeys.includes(eventKey);
|
|
};
|
|
function isObject(value) {
|
|
return value !== null && _typeof(value) === 'object' && !Array.isArray(value);
|
|
}
|
|
|
|
/**
|
|
* 通过子元素找到父级节点
|
|
* @param objects
|
|
* @param element
|
|
* @returns
|
|
*/
|
|
export var findParentByChild = function findParentByChild(objects, propertyValue) {
|
|
var propertyKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'key';
|
|
for (var i = 0; i < objects.length; i++) {
|
|
var obj = objects[i];
|
|
if (obj[propertyKey] === propertyValue) {
|
|
return obj;
|
|
} else if (_typeof(obj) === 'object') {
|
|
var found = findParentByChild(Object.values(obj), propertyValue);
|
|
if (found) {
|
|
return obj;
|
|
}
|
|
}
|
|
}
|
|
return null; // 如果找不到包含具有指定属性的子对象的父对象,返回 null
|
|
};
|
|
export var getAllRootKeyById = function getAllRootKeyById(val, list) {
|
|
var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'key';
|
|
var keys = [];
|
|
var findParentByChild = function findParentByChild(propertyValue, objects, propertyKey) {
|
|
for (var i = 0; i < objects.length; i++) {
|
|
var obj = objects[i];
|
|
if (obj[propertyKey] === propertyValue) {
|
|
console.log('obj', obj);
|
|
return obj;
|
|
} else if (_typeof(obj) === 'object') {
|
|
var found = findParentByChild(propertyValue, Object.values(obj), propertyKey);
|
|
if (found) {
|
|
if (isObject(found)) {
|
|
keys.push(found.key);
|
|
}
|
|
return obj;
|
|
}
|
|
}
|
|
}
|
|
return null; // 如果找不到包含具有指定属性的子对象的父对象,返回 null
|
|
};
|
|
var data = findParentByChild(val, list, key);
|
|
data.key && keys.push(data.key);
|
|
return {
|
|
root: data,
|
|
keys: keys
|
|
};
|
|
}; |