CollectionFS,Meteor.js,Summernote(WYSIWYG)和文件上传 [英] CollectionFS, Meteor.js, Summernote(WYSIWYG) and file upload
问题描述
我正在使用Meteor.js,Summernote和Collection FS开发一个项目。
I'm working on a project using Meteor.js, Summernote and 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());
});
}
});
插入的图像成功进入指定的图像存储网址。这是CollectionFS的javascript。
The image when inserted does successfully go into the specified URL for image storage. Here is the 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函数。但是,我还是没有运气。
I was wondering if anyone could guide me in the right direction. I've been told the URL on callback is not defined. So, I've been asked to try this code, using a setTimeout function. However, I've still had no luck.
onImageUpload: function(files, editor, $editable) {
Images.insert(files[0], function (err, fileObj) {
setTimeout(function() {
editor.insertImage($editable, fileObj.url());
}, 300)
});
}
有没有人在Meteor.js和collectionFS中通过这种方式使用summernote?
Has anyone succeeded through using summernote in this manner in Meteor.js and collectionFS?
如果有,请帮助我。如果这解决了,我会为许多meteor.js用户发布一个教程。我相信这将是一个很大的贡献。
If so, please help me. If this gets solved, I'll be posting a tutorial for many meteor.js users. I believe it will be a great contribution.
此外,即使你不使用Meteor.js或CollectionFS,如果你可以在你的两分钱,非常感谢。
Also, even if you're not using Meteor.js or CollectionFS, if you can pitch in your two cents, it would be greatly appreciated.
谢谢!
推荐答案
除了使用setTimeout:
Here is another solution besides using 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();
}
});
});
}
});
}
这篇关于CollectionFS,Meteor.js,Summernote(WYSIWYG)和文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!