我正在 Wordpress 中构建一个使用 react 的 Gutenberg 块,我想要实现的是,当单击 div 时,它应该设置带有子页面 id 的属性。array.map() 用于创建每个具有必须单击的动态值的潜水。
const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks
const { RichText } = wp.editor;
const { withSelect } = wp.data;
const { Fragment, Component } = wp.element;
const {InspectorControls, PanelColorSettings, BlockControls, BlockAlignmentToolbar,MediaUpload } = wp.editor;
const {
RangeControl,
SelectControl,
TextControl,
ToggleControl,
Dashicon,
IconButton,
Button,
Toolbar,
PanelBody,
RadioControl,
TabPanel,
} = wp.components
const {
attributes,
setAttributes,
} = this.props;
const {
subpagesArray,
indexArray,
align,
currentSelected,
displayPageExcerpt,
displayPageIcon,
displayPageTitle
} = attributes;
<section className="gosign-content-nav-block">
{subpagesArray.map(subpage => {
return (
<div className="subpage-block" onClick ={() => {setAttributes({currentSelected : subpage.id});}} >
{displayPageIcon &&
<div className="subpage-icon">
<span className="accessibility">
<i className="material-icons">accessibility</i>
</span>
</div>
}
{displayPageTitle &&
<div className="subpage-title">
<p>{subpage.title.rendered}</p>
</div>
}
</div>
)
})}
</section>
在我看来,这是一些“这个”参考问题。如果我能得到快速帮助,那就太好了。