wordpress - 将属性从父级传递给子级 Gutenberg Blocks
问题描述
如何传递父属性或传递内部子块中的一些道具?
<InnerBlocks allowedBlocks={[ 'groupama-blocks/block-08']}/>
例如,我想将此块属性添加到块 08,我将作为内部块添加。
解决方案
将数据从父母传递给孩子 GUTENBERG
家长
const {useSelect, dispatch, select} = wp.data;
edit: (props) => {
const {
clientId
} = props;
var children = select('core/block-editor').getBlocksByClientId(clientId).[0].innerBlocks;
children.forEach(function(child){
dispatch('core/block-editor').updateBlockAttributes(child.clientId, {label: 'Hello'})
});
孩子
let parent = select('core/block-editor').getBlockParents(clientId);
const parentAttributes = select('core/block-editor').getBlockAttributes(parent);
console.log(parentAttributes); // Block Attributes
console.log(props.attributes.label); // Passing Props
推荐阅读
- excel - 如果出现错误,则出现“下一步”问题“错误”结束 VBA
- angular - Angular 6验证数字输入
- azure - 无法使用 NotificationHub + ApnsCredentials 部署 arm 模板
- scala - 错误:值 toDF 不是 org.apache.spark.rdd.RDD[org.apache.kafka.clients.consumer.ConsumerRecord[String,String]] 的成员
- c# - 如何从winforms中的Outlook电子邮件中获取附件?
- clojure - 我可以强制 lein 忽略当前 Clojure 项目外部任何代码的依赖关系吗?
- android-studio - Android Studio 代理设置
- angular - 如何将值从一个组件传递给服务以获取 Angular 6 中的第二个组件?
- iis - URL 重写回参考操作 URL 不起作用
- excel - 如何确保宏工作簿在关闭其他工作簿时不会关闭