我有一个带有属性的自定义古腾堡块:
valuesObj: {
type: 'object',
default: {},
}
我想在输入更改时更新该对象内的特定属性。所以我创建了一个函数来调用onChange
在组件上:
<TextInput
value={ valuesObj[index] }
onChange={ (value) => this.onChangeValue(value, index) }
/>
这是被调用的函数:
onChangeValue(value, index) {
var newValuesObj = this.props.attributes.valuesObj;
newValuesObj[index] = value;
this.props.setAttributes({ valuesObj: newValuesObj });
};
由于某种原因,这似乎根本不起作用。当我输入TextInput
没有什么变化。当我保存帖子时,该属性没有保存任何内容。我知道该函数正在被正确调用并且正在传递正确的value
and index
(I console.log
他们)。我一直在搜索古腾堡文档,但它似乎没有提到任何相关内容。
不确定我错过了什么/做错了什么。
你正在呼唤onChangeURL
,但你的方法被称为onChangeValue
.
我不知道价值在哪里index
来自但尝试在您的中创建一个新对象onChangeValue
并为您的属性设置这个新对象。
尝试改变你的onChangeValue
像这样的东西:
onChangeValue(value, index) {
var newValuesObj = {};
newValuesObj[index] = value;
this.props.setAttributes({ valuesObj: newValuesObj });
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)