Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
background-size with values cover , contain or 100% 100% depending on the desired behavior.
So you have it. Only possible background-position: 50% 50%;
If you want to enter it completely, then not cover but contain.
const categories = [
{ id: 1, name: 'name 1', parent: null },
{ id: 2, name: 'name 2', parent: 1 },
{ id: 3, name: 'name 3', parent: 6 },
{ id: 4, name: 'name 4', parent: 5 },
{ id: 5, name: 'name 5', parent: 6 },
{ id: 6, name: 'name 6', parent: null },
{ id: 7, name: 'name 7', parent: null }
];
function buildTree(items, parent) {
parent = parent || null;
let result = [];
items.forEach((item) => {
if (item.parent === parent) {
result.push(item);
item.children = buildTree(items, item.id);
if (!item.children.length) {
delete item.children;
}
}
});
return result;
}
// todo: не обходить уже добавленные
console.log(buildTree(categories));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question