gpt4 book ai didi

Node.js (sails.js) 所见即所得编辑器 - 图片

转载 作者:搜寻专家 更新时间:2023-10-31 22:36:55 24 4
gpt4 key购买 nike

Is there a way to use any WYSIWYG/html editor in the sails app? I can't find any manuals to do that. Seems like Mercury is well-supported in Node but I can't find a way to adapt sails for it either. :( Please guide me

现在好了,事实证明连接 TinyMCE 很容易(就像 http://www.tinymce.com/wiki.php/Installation 中描述的一样简单)。所以现在另一个主要问题出现了:是否有任何 Node.js 连接器可以连接到任何编辑器以上传图像和东西?

或者我怎样才能允许用户上传图片并将其插入到帖子正文中?

谢谢

最佳答案

耶!终于成功了!

最后我使用了 CKEditor,它成功了!检查一下:

  • http://ckeditor.com/download 下载编辑器
  • 放入你项目的assets文件夹
  • config.filebrowserUploadUrl = '/uploader'; 添加到您的 ckeditor/config.js 文件
  • 在您的 Controller 中添加上传操作:

upload_file : function(req, res) {

var fs = require('fs');
console.log(req.files);

fs.readFile(req.files.upload.path, function (err, data) {
var newPath = 'assets/files/' + req.files.upload.name;
fs.writeFile(newPath, data, function (err) {
if (err) res.view({err: err});
html = "";
html += "<script type='text/javascript'>";
html += " var funcNum = " + req.query.CKEditorFuncNum + ";";
html += " var url = \"/files/" + req.files.upload.name + "\";";
html += " var message = \"Uploaded file successfully\";";
html += "";
html += " window.parent.CKEDITOR.tools.callFunction(funcNum, url, message);";
html += "</script>";

res.send(html);
});

});

}

  • 为此操作添加路由:
'/uploader' : {
controller : 'post',
action : 'upload_file'
}
  • 为我创建一个文件夹(assets/files)用于上传
  • 最后,更改将 ckeditor 放入的表单:
block body
script(type="text/javascript", src="/ckeditor/ckeditor.js")
form(action='/posts/create', method="post", enctype="multipart/form-data")
p Title
input(type='text', name='title')
p Body
textarea(name='body', id='ck')
script.
CKEDITOR.replace( 'ck' );
hr
input(type='submit', value='Сохранить')

(这里是 Jade )

就是这样!享受所见即所得:)

关于Node.js (sails.js) 所见即所得编辑器 - 图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21378630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com