我想编辑一个现有的块来添加另存为元数据的检查器控件。我一直在绞尽脑汁寻找如何保存数据。以下代码向inspector系统添加了一个文本字段。我可以添加该字段,但由于某些原因,该字段无法保存。我一辈子都想不出来。
var el = wp.element.createElement,
Fragment = wp.element.Fragment
registerBlockType = wp.blocks.registerBlockType,
RichText = wp.editor.RichText,
BlockControls = wp.editor.BlockControls,
AlignmentToolbar = wp.editor.AlignmentToolbar,
Fields = wp.components;
var withInspectorControlsEdit = wp.compose.createHigherOrderComponent( function( BlockEdit ) {
return function( props ) {
return el(
wp.element.Fragment,
{},
el( BlockEdit, props ),
el(
wp.editor.InspectorControls,
{},
el(
Fields.PanelBody,
{},
el(
Fields.TextControl,
{
label: \'Test Field\',
value: props.attributes.testField,
onChange: function(e){
props.setAttributes({ testField: e });
}
}
)
)
)
)
};
}, \'withInspectorControlsEdit\' );
wp.hooks.addFilter( \'editor.BlockEdit\', \'acf/accordion\', withInspectorControlsEdit );