首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >古腾堡.updateBlock

古腾堡.updateBlock
EN

Stack Overflow用户
提问于 2019-06-15 00:37:43
回答 1查看 869关注 0票数 2

我相信我可以使用一些方法来满足我的需求。然而,我需要它的一个例子使用:https://developer.wordpress.org/block-editor/data/data-core-editor/#updateBlockAttributes这是怎么可能的?也许有人有它?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-16 22:05:00

您可以在Block Editor Handbook中阅读有关该函数的(非常小的)文档。这是一个来自我在new slider block for wordpress的代码的活生生的例子。它使用withDispatch高阶组件为组件提供操作。

代码语言:javascript
复制
withDispatch( ( dispatch, ownProps, registry ) => {

  return {
    updateEditable( isEditing ) {
      const { clientId, setAttributes } = ownProps;
      const { getBlockOrder } = registry.select( 'core/block-editor' );
      const { updateBlockAttributes } = dispatch( 'core/block-editor' );

      //update own isEditable
      setAttributes( { isEditing } );

      const innerBlockIds = getBlockOrder( clientId );
      innerBlockIds.forEach( ( innerBlockId ) => {
        updateBlockAttributes( innerBlockId, {
         isEditing,
        } );
      } );
    },
  };
} )

要使用wordpress数据模块,它向客户端提供有关编辑器或块的数据,您还可以使用wp.data-Module。当在后台时,你可以进入浏览器控制台,输入wp.data.dispatch( 'core/editor' ).updateBlockAttributes()来测试函数的作用。

您还可以查看gutenberg github存储库。核心块也使用updateBlockAttributes。例如在columns

如果你想了解更多关于古腾堡数据处理的信息,你可以阅读这篇很好的blob文章,它介绍了wp.data应用编程接口以及withSelectwithDispatch高阶组件的概念。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56602189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档