我相信我可以使用一些方法来满足我的需求。然而,我需要它的一个例子使用:https://developer.wordpress.org/block-editor/data/data-core-editor/#updateBlockAttributes这是怎么可能的?也许有人有它?
发布于 2019-06-16 22:05:00
您可以在Block Editor Handbook中阅读有关该函数的(非常小的)文档。这是一个来自我在new slider block for wordpress的代码的活生生的例子。它使用withDispatch高阶组件为组件提供操作。
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应用编程接口以及withSelect和withDispatch高阶组件的概念。
https://stackoverflow.com/questions/56602189
复制相似问题