下面的RadioControl属性保存数据,但未选中选定的无线电。我认为状态没有更新,或者我在selected
属性
我查看了文档,https://developer.wordpress.org/block-editor/components/radio-control 还有林达系列https://www.lynda.com/WordPress-tutorials/WordPress-Developing-Blocks-Gutenberg/5034179-2.html
在下面的代码中,组件在下面与块的其余部分隔离。
import { registerBlockType } from \'@wordpress/blocks\';
import { RadioControl } from \'@wordpress/components\';
// Import our CSS files
import \'./style.scss\';
import \'./editor.scss\';
registerBlockType( \'dynamic-equine/radio\', {
title: \'DE Radio\',
icon: \'media-document\',
category: \'dynamic-equine\',
attributes: {
position: {
type: \'text\',
selector: \'.position\',
},
},
edit( { attributes, setAttributes } ) {
const positionHandler = function( position ) {
return setAttributes( {
position: position,
} );
}
return (
<div className="container de_radio serviceCard">
<RadioControl
label="Image Position"
selected={ attributes.positon }
className="position"
options={ [
{ label: \'Left\', value: \'left-align\' },
{ label: \'Right\', value: \'right-align\' },
] }
onChange={ positionHandler }
/>
</div>
);
},
save( { attributes } ) {
return (
<div className="radio">
{attributes.position}
</div>
);
},
} );
如果您能提供任何帮助,我们将不胜感激。