大家好。使用 @angus 提供的代码 此处,并参考 GitHub 仓库,我能够很好地实现主题自定义字段功能——除了无法在编辑器的“头部”区域(即通常可以编辑分类的地方,也就是 edit-topic 连接器中)对其进行编辑。
我已经按照仓库中的代码进行了操作,包括 plugin.rb 文件及其他地方的代码。例如,我在文件 connectors/edit-topic/edit-topic-custom-field-container.hbs 中添加了输入框(类似于 此处):
{{#if isString}}
{{input
type="text"
value=(readonly fieldValue)
class="topic-custom-field-input large"
input=(action "onChangeField" value="target.value")
placeholder=(i18n 'topic_custom_field.placeholder' field=fieldName)
}}
{{/if}}
此外,我还添加了 topic-custom-field-initializer 中的代码,如下所示:
api.registerConnectorClass('edit-topic', 'edit-topic-custom-field-container', {
setupComponent(attrs, component) {
const model = attrs.model;
let props = {
fieldName: fieldName,
fieldValue: model.get(fieldName)
}
component.setProperties(Object.assign(props, fieldInputTypes(fieldType)));
},
actions: {
onChangeField(fieldValue) {
this.set(`buffered.${fieldName}`, fieldValue);
}
}
});
...
api.serializeOnCreate(fieldName);
api.serializeToDraft(fieldName);
api.serializeToTopic(fieldName, `topic.${fieldName}`);
但是:虽然仓库中的其他代码对我有效(例如在编辑器中成功添加自定义字段值),且我没有收到任何错误,但我无法保存在 edit-topic 连接器输入框中输入的值。如果我在其中输入一个值,保存编辑后该值就会消失。
是否可能需要其他步骤才能在 edit-topic 连接器中保存值?