mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-01 13:40:41 +00:00
28 lines
717 B
JavaScript
28 lines
717 B
JavaScript
export function getIdsFromSchema(schema, ids = []) {
|
|
if (!schema) return ids;
|
|
const { componentName, id, children } = schema;
|
|
if (componentName) {
|
|
ids.push(id);
|
|
}
|
|
if (Array.isArray(children) && children.length > 0) {
|
|
children.forEach(node => getIdsFromSchema(node, ids));
|
|
}
|
|
return ids;
|
|
}
|
|
|
|
export function getNodeFromSchemaById(schema, _id) {
|
|
if (!schema) return null;
|
|
const { id, children } = schema;
|
|
let retNode = null;
|
|
if (_id === id) return schema;
|
|
if (Array.isArray(children) && children.length > 0) {
|
|
children.some(node => {
|
|
retNode = getNodeFromSchemaById(node, _id);
|
|
if (retNode) {
|
|
return true;
|
|
}
|
|
return false;
|
|
});
|
|
}
|
|
return retNode;
|
|
} |