英文:
Gutenberg: how to restrict the number of blocks inside InnerBlocks
问题
const innerBlocksCount = innerBlocks.length;
if (innerBlocksCount > allowedBlocksCount) {
innerBlocks.slice(0, allowedBlocksCount);
return (
<InnerBlocks renderAppender={() => false} />
);
}
我正在尝试为WordPress中的列块创建一个克隆,用户将选择放入1个、2个或3个块,我的块工作正常,但当用户放入3个块然后选择1个时,我希望移除最后的2个块,我该如何实现这样的功能,因为我已经尝试了几种方法。
英文:
const innerBlocksCount = innerBlocks.length;
if (innerBlocksCount > allowedBlocksCount) {
innerBlocks.slice(0, allowedBlocksCount);
return (
<InnerBlocks renderAppender={() => false} />
);
I'm trying to make a clone for the column block in wordpresss,where the user will select either 1 or 2 or 3 blocks to put in, my block works fine but when the user put 3 blocks and then select 1, I want the last 2 blocks to be removed,
how can I achieve something like that as I have tried several things
答案1
得分: 1
你可以识别需要删除的块的客户端 ID,并将其作为参数传递给 removeBlocks 函数。
英文:
you can identify the client Ids of the blocks required to be deleted and pass it as a parameter to removeBlocks function
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论