@wufengteam/wform
Version:
@wufengteam/wform
31 lines • 1.04 kB
JavaScript
export var getCompPropsByIdMap = function getCompPropsByIdMap(data) {
var result = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// eslint-disable-next-line consistent-return
data.forEach(function (item) {
var _ref = item || {},
id = _ref.id,
props = _ref.props,
components = _ref.components;
result[id] = props;
if (components && Array.isArray(components) && components.length > 0) {
return getCompPropsByIdMap(components, result);
}
});
return result;
};
export var getCompPropsById = function getCompPropsById(data, attrCode) {
if (!(data && Array.isArray(data) && data.length > 0)) return {};
for (var i = 0; i < data.length; i += 1) {
var _ref2 = data[i] || {},
id = _ref2.id,
props = _ref2.props,
components = _ref2.components;
if (id === attrCode) {
return props;
}
if (components && Array.isArray(components) && components.length > 0) {
return getCompPropsById(components, attrCode);
}
}
return {};
};