javascript - CollectionFS Meteor、所见即所得、Summernote、图片上传

标签 javascript collections meteor wysiwyg summernote

大家晚上好。

我一直在努力使用所见即所得编辑器和 collectionFS 在 Meteor 中上传文件。我一直在尝试使用 Summernote,但我不介意使用 Redactor 或 Froala。

我显然不够熟练,无法将所见即所得编辑器与 CollectionFS 连接以将文件上传到本地路径。

这是我的代码。

Template.postSubmit.rendered = function(){
    $('#edit').summernote();

};


Template.postSubmit.events({
  'submit #postSubmit':function(event, template) {
    FS.Utility.eachFile(event, function(file) {
      Images.insert(file, function (err, fileObj) {
        //Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
      });
    });
  }
});

Images = new FS.Collection("images", {
  stores: [new FS.Store.FileSystem("images", {path: "img2"})]
});

Images.allow({
    insert: function() {
        return true;
    },
    update: function() {
        return true;
    },
    remove: function() {
        return true;
    },
    download: function() {
        return true;
    }
});

根据我的浅薄知识,我必须添加

onImageUpload: function(files, editor, welEditable) {
                        sendFile(files[0],editor,welEditable);
                       }

在 Summernote 脚本中(是吗?)。

我似乎无法完成这项工作!指针、指南和帮助将不胜感激......

编辑1:

Template.postSubmit.rendered = function(){
    $('#edit').summernote({
        onImageUpload: function(file) {
    FS.Utility.eachFile(event, function(file) {
      Images.insert(file, function (err, fileObj) {
        //Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
      });
    });
  } 
    });
};

所以我已经编辑了我的代码,现在它可以工作了!它将文件上传到指定路径。现在的问题是, 1.它会立即上传图像(当我单击“添加图像”时,而不是在我提交表单时)。 2. 上传的图片不会在编辑器中显示。

最佳答案

这对我有用:

Template.blogList.rendered = function() {
    var template = this;
    $('#summernote').summernote({
        height: 400,
        maxHeight:800,
        minHeight:250,
        onImageUpload: function(files, editor, $editable) {

            Images.insert(files[0], function (err, fileObj) {
                console.log("after insert:", fileObj._id);
                template.autorun(function (c) {
                  fileObj = Images.findOne(fileObj._id);
                  var url = fileObj.url();
                  if (url) {
                    $("#summernote").summernote("insertImage", fileObj.url(), "Image Title"); 
                    c.stop();
                  }
                });
            });

        }   
    });
}

关于javascript - CollectionFS Meteor、所见即所得、Summernote、图片上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27345800/

相关文章:

javascript - 限制跨域 Ajax 请求

javascript - 改进 JavaScript 功能

javascript - 如何在 JavaScript 中从对象内部访问属于同一对象的属性?

Java 8 按具有不同分隔符的第一个字符串属性进行分组

javascript - 如何在meteorjs中向数据表添加复选框

javascript - 如何通过单击另一张图像来更改带有过渡的 img src

java - 空指针异常 - 迭代 FastMap 值

java - 将多重集转换为 map

javascript - Meteor 方法调用 - 等待方法完成

javascript - Meteor .depends() 方法