你不需要propstwo
. 它没有任何作用。只有一个props
参数,并使用它访问块的attributes
. 二者都header
和content
是属性,因此可以通过相同的props
参数:
wp.blocks.registerBlockType(\'myblock/question-block\', {
title: \'Blok Pytan\',
icon: \'dashicons-welcome-write-blog\',
category: \'common\',
attributes: {
header: {
type: \'string\'
},
content: {
type: \'string\'
}
},
edit: function(props) {
function updateheader(event) {
props.setAttributes({
header: event.target.value
})
}
function updatecontent(event) {
props.setAttributes({
content: event.target.value
})
}
return wp.element.createElement(
"div",
null,
wp.element.createElement(
"h2",
null,
"Nagłówek tekstu"
),
wp.element.createElement(
"input",
{
type: "text",
value: props.attributes.header,
onChange: updateheader
}
),
wp.element.createElement(
"p",
null,
"Rozwijany tekst"
),
wp.element.createElement(
"input",
{
type: "text",
value: props.attributes.content,
onChange: updatecontent
}
),
),
},
save: function(props) {
return wp.element.createElement(
"div",
{
className: "accodrion",
},
wp.element.createElement(
"h2", {
className: "accodrdion-header"
},
props.attributes.header
),
wp.element.createElement(
"p", {
className: "panel"
},
props.attributes.content
)
)
}
})
您还没有将子元素正确嵌套在
edit
函数,我在上面也对其进行了更正。