【问题标题】:CollectionFS, Meteor.js, Summernote(WYSIWYG) and file uploadCollectionFS、Meteor.js、Summernote(所见即所得)和文件上传
【发布时间】:2015-02-11 12:10:28
【问题描述】:

我正在使用 Meteor.js、Summernote 和 Collection FS 开展一个项目。

首先,这是我的代码。

Template.postSubmit.rendered = function() {
   $('#summernote').summernote({
        height: 400,
        maxHeight:800,
        minHeight:250,
        onImageUpload: function(files, editor, $editable) {
        Images.insert(files[0], function (err, fileObj) {
            editor.insertImage($editable, fileObj.url());    
        });
      }
   });

插入后的图像确实成功进入指定的 URL 以进行图像存储。这是 CollectionFS javascript。

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

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

我想知道是否有人可以引导我朝着正确的方向前进。我被告知回调的 URL 没有定义。因此,我被要求使用 setTimeout 函数尝试此代码。但是,我仍然没有运气。

onImageUpload: function(files, editor, $editable) {
        Images.insert(files[0], function (err, fileObj) {
          setTimeout(function() {
            editor.insertImage($editable, fileObj.url());
          }, 300)
        });
      }

有没有人以这种方式在 Meteor.js 和 collectionFS 中成功使用summernote?

如果是这样,请帮助我。如果这个问题得到解决,我将为许多流星.js 用户发布教程。我相信这将是一个巨大的贡献。

另外,即使您不使用 Meteor.js 或 CollectionFS,如果您能投入两分钱,我们将不胜感激。

谢谢!

【问题讨论】:

    标签: javascript file-upload collections meteor summernote


    【解决方案1】:

    这是除了使用 setTimeout 之外的另一种解决方案:

    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();
                      }
                    });
                });
    
            }   
        });
    }
    

    【讨论】:

    • 是时候删除你的反对票了。与你相反,我现在发布了一个有效的答案。
    • 酷 - 很高兴您可以将帖子的类型从问题(正如您在已删除的评论中所说的 ;-) 更改为解决方案
    猜你喜欢
    • 2015-02-05
    • 2014-08-21
    • 2015-09-10
    • 2016-04-19
    • 2015-07-21
    • 2014-03-21
    • 2015-07-10
    • 2018-06-19
    • 1970-01-01
    相关资源
    最近更新 更多