我有一个页面组件(五为什么),用户可以选择一些输入来完成输入。当用户单击“完成”时,将禁用所有问题。
five-whys.hbs:
{{#each this.whys as |why i|}}
<Generic::RichTextInput
@value={{why.content}}
@onChange={{action this.whyChanged i}}
@disabled={{this.isFinalized}} />
{{/each}}
<button {{on "click" this.finalizeWhy}}>Finalize</button>
5-whys.ts
interface AnalyzeFiveWhysArgs {
dataStory: DataStory;
}
export default class AnalyzeFiveWhys extends Component<AnalyzeFiveWhysArgs> {
@alias("args.dataStory.fiveWhysAnalysis") fiveWhysAnalysis
@tracked
isFinalized: boolean = this.fiveWhysAnalysis.isFinalized ?? false;
@tracked
whys: LocalWhy[] = this.fiveWhysAnalysis.whys;
@tracked
isFinalized: boolean = this.fiveWhysAnalysis.isFinalized ?? false;
@action
async finalizeWhy() {
this.isFinalized = true;
}
当我的RTF组件只是常规文本区域时,此方法很好用。但是,我正在尝试实现tinymce,这需要我在余烬之外做些安全的魔术空间。
模板:
<textarea id={{this.id}} disabled={{this.templatePieceIsDisabled}}>{{@value}}</textarea>
打字稿:
interface GenericRichTextInputArgs {
value?: string;
onChange: (value: string) => void;
name: string;
disabled?: boolean;
}
export default class GenericRichTextInput extends Component<GenericRichTextInputArgs> {
constructor(owner: unknown, args: GenericRichTextInputArgs) {
super(owner, args);
this.initializeTinymce();
}
id = this.args.name;
get editor() {
return tinymce.get(this.id);
}
get settings() {
console.log(this.args.disabled);
const settings: TinyMCESettings = {
selector: `#${this.id}`,
setup: (editor: Editor) => this.setupEditor(this, editor),
readonly: this.args.disabled ? this.args.disabled : false
};
return settings;
}
initializeTinymce() {
Ember.run.schedule('afterRender', () => {
console.log("re-initializing"); // I expect to see this log every time the isFinalized property in the five-whys component changes. But I only see it on page load.
tinymce.init(this.settings);
});
}
setupEditor(self: GenericRichTextInput, editor: Editor) {
... // details of tinymce API
}
}
当我单击“完成”按钮时,RTF组件中的禁用标志的效果不会改变。
我正在使用的tinymce库将文本区域显示设置为none,将aria-hidden隐藏为true。这是因为它将文本区域包装在小部件中。因此,我必须使用库的api来设置为禁用。
答案 0 :(得分:0)
我知道了。 Ember不会为更新生命周期事件运行构造函数。因此,当模板重新呈现时,我需要告诉Ember重新运行初始化程序。我必须使用https://github.com/emberjs/ember-render-modifiers来做到这一点。
所以我的RTF编辑器模板如下所示:
<textarea
id={{this.id}}
{{did-update this.updateDisabled @disabled}}>
{{@value}}
</textarea>
我在富文本编辑器后面的代码中添加了此操作:
@action
updateDisabled(element: HTMLTextAreaElement, [disabled]: any[]) {
this.disabled = disabled;
this.editor.destroy();
this.initializeTinymce();
}