gutenberg blocks loop through multiple innerBlocks
-
I just want to retrieve the information of an innerblock contained in X innerblocks.
Can someone explain to me the bug here??
What would be the “right way” to perform this operation?function getSubChildBlockByLevel(childBlock, loop){ loop++; if(loop < attributes.lvlchild){ getSubChildBlockByLevel(childBlock[0]?.innerBlocks, loop); } else { console.log("In_Function--------"); console.log(childBlock); return childBlock; } } var loop = 0; var childBlock = select('core/block-editor').getBlocksByClientId(clientId)[0].innerBlocks console.log("First ChildBlock--------"); console.log(childBlock); var subChildBlock = getSubChildBlockByLevel(childBlock, loop); console.log("After_Return--------"); console.log(subChildBlock);
Console return :
// With : "attributes.lvlchild" = 2 First ChildBlock-------- 0: attributes: {...} clientId: "8ae88548-b53b-4bc6-9eb8-8c57ba68c9fd" innerBlocks: Array(1) 0: attributes: {...} clientId: "f72a3307-0488-4bf6-827c-00e8e2b2f43b" innerBlocks: (4) (...) In_Function-------- 0: attributes: { } clientId: "f72a3307-0488-4bf6-827c-00e8e2b2f43b" innerBlocks: (4) (...) After_Return-------- undefined
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘gutenberg blocks loop through multiple innerBlocks’ is closed to new replies.