以下是从文本编辑器中删除附件的功能。通过“ X”按钮调用一次后,只要您在文本区域内单击即可调用它。使用的编辑器库-draft.js。如何停止意外调用removeFiles()。
private removeFiles = (id: any) => {
debugger;
unmountComponentAtNode(document.getElementById(id));
document.getElementById(id).remove();
const newState = this.state;
newState.uploadFiles.splice(id, 1);
newState.files.splice(id, 1);
newState._attachments.splice(id, 1);
this.setState(newState);
}
public fileSelectEvent = (filesArray: any) => {
debugger;
var files = (document.getElementById('fileInput') as HTMLInputElement).files;
var editorElement = document.getElementsByClassName('DraftEditor-editorContainer');
if (!(!filesArray)) {
this.readFiles(filesArray, false);
for (let i = 0; i < files.length; i++) {
var newDiv = document.createElement('div');
console.log(files[i].name, '{files[i].name}----');
newDiv.innerHTML = `<div class=${styles.fileBox} id=${i}>
<span>${files[i].name}</span>
<h5 ${onclick = () => this.removeFiles(i)}>X</h5>
<div>`;
editorElement[0].appendChild(newDiv);
}
}
}