力皓 66d43f2103 fix: convertI18nObject
fix: initialChildren 传入 settingTopEntry 参数
2020-10-16 17:31:02 +08:00

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;
}