javascript - 为编辑器保存块内容
问题描述
我有一个自定义的 WordPress 块,在编辑中我添加了一个 window.onload = function() 我正在使用 JavaScript 插件向图像添加多边形,在编辑器中它看起来很好并且可以在控制台中看到数据,但我无法存储这些数据如何保存。
edit: function( props ) {
function onChangeTitle(newTitle)
{
props.setAttributes({ title: newTitle.target.value })
}
function onChangeMediaURL(mediaURL)
{
props.setAttributes({ mediaURL: mediaURL.target.value });
}
return wp.element.createElement(
wp.element.Fragment,
null,
wp.element.createElement(
InspectorControls,
null,
wp.element.createElement(PanelBody, {
title:'Panel Title',
initialOpen: true
},
wp.element.createElement
(
"p",
null,
"Add Title"
),
wp.element.createElement
(
"input", { type: "text",
value: props.attributes.title,
onChange: onChangeTitle }
),
wp.element.createElement
(
"p",
"Add Image URL"
),
wp.element.createElement
(
"input", { type: "text",
value: props.attributes.mediaURL,
onChange: onChangeMediaURL }
),
)
),
wp.element.createElement(
wp.blockEditor.RichText.Content, {
tagName: 'h2',
className: props.className,
value: props.attributes.title,
}
),
wp.element.createElement('img', {id:"annoimg",src: props.attributes.mediaURL, style: {display:"block"}}),
window.onload = function() {
var formatter = function(annotation) {
var contributors = [];
annotation.bodies.forEach(function(body) {
if (body.creator)
contributors.push(body.creator.id);
});
if (contributors.length > 1) {
return {
'data-users': contributors.join(', '),
'style': 'stroke-width:2; stroke: red'
}
}
}
var anno = Annotorious.init({
image: document.getElementById('annoimg'),
locale: 'auto',
formatter: formatter
});
anno.on('createAnnotation', function(annotation) {
console.log(annotation); //Data Needed
anno.saveSelected(annotation);
});
},
);
},
我发送到控制台的注释是我需要的数据,我试图将它保存到像标题这样的属性图像但不工作,我将如何保存这些数据。
解决方案
推荐阅读
- sql - SQL Query 将行转换为 MS Access 数据库中的列
- java - java.lang.OutOfMemoryError:Java 堆空间异常
- c# - 一次跨行中的所有项目的Linq搜索(.Contains)?
- node.js - 不可靠的 npm 安装在 docker 容器中
- installation - 在 Ubuntu 中安装 Corda Demobench
- ruby-on-rails - Rails Hash 复杂组,最小值为 2,最大值为
- python - 在Python中的变量中传递列表的每个部分?
- java - Spring Boot v2.0 看不到模板
- rest - HttpClient.SendRequest 异常
- python - 在 Python 中获取或构建 PEM 证书链