【问题标题】:Custom cell editor for input type file in tabulator制表器中输入类型文件的自定义单元格编辑器
【发布时间】:2020-12-15 11:37:16
【问题描述】:

我正在尝试为输入类型文件(图像)集成自定义编辑器

editor: fileEditor,

还有一个函数叫做fileEditor

var fileEditor = function (cell, onRendered, success, cancel, editorParams) {
    var cellId = cell.getRow().getData()._id;
    
    var uploadTo = document.createElement("input");
    uploadTo.setAttribute("type", "hidden");
    uploadTo.setAttribute("name", "uploadTo");
    uploadTo.setAttribute("id", "uploadTo");
    uploadTo.setAttribute("value", "images/category");

    var editor = document.createElement("input");
    editor.setAttribute("type", "file");
    editor.setAttribute("name", "imgFile");
    editor.setAttribute("id", cellId+"_imgFile");
    editor.style.padding = "3px";
    editor.style.width = "100%";
    editor.style.boxSizing = "border-box";
    
    onRendered(function () {
        editor.focus();
        editor.style.css = "100%";
    });
    function successFunc() {
        console.log(cell, editor.value)
        if(editor.value != ""){
            // cell.setValue(editor.value, true)
            success(editor.value);
            updateCategoryImage(cell, cell.getColumn().getField(), cell.getRow().getData()._id)
        }else{
            cell.cancelEdit();
        }
    }
    editor.addEventListener("change", successFunc);
    return editor;
};

在 updateCategoryImage() 中,我尝试使用 formdata 将此图像上传到 s3,但文件元素在 DOM 中不存在。请帮我解决这个问题。

谢谢。

【问题讨论】:

    标签: javascript node.js tabulator


    【解决方案1】:

    一旦编辑器触发了成功函数,元素就会被销毁(然后立即被单元格值替换),所以你应该在调用@之前调用你的updateCategoryImage函数987654322@

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 2012-08-05
      相关资源
      最近更新 更多