Gutenberg:如何限制InnerBlocks内部块的数量

huangapple go评论90阅读模式
英文:

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 &gt; allowedBlocksCount) {
    innerBlocks.slice(0, allowedBlocksCount);

    return (
      &lt;InnerBlocks renderAppender={() =&gt; false} /&gt;
    );

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

huangapple
  • 本文由 发表于 2023年5月6日 19:57:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76188735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定