javascript - CKfinder 多图上传,无需 CKEditor
问题描述
我正在使用没有 CKEditor 的 ckfinder 模式将多个文件上传到表单部分。
我使用了文档部分中提供的代码,
CKfinder 模态按预期打开,选择了多个文件,但我无法获取所有图像 url。我得到的回应只有第一张图片。
window.CKFinder = {
_popupOptions: {
'popup-1-config': { // Config ID for first popup
chooseFiles: true,
onInit: function( finder ) {
finder.on( 'files:choose', function( evt ) {
var file = evt.data.files.first();
var output = document.getElementById( 'output' );
output.innerHTML = 'Selected in popup 1: ' + file.get( 'name' ) + '<br>URL: <img src=" ' + file.getUrl() + '">';
} );
}
},
}
};
var popupWindowOptions = [
'location=no',
'menubar=no',
'toolbar=no',
'dependent=yes',
'minimizable=no',
'modal=yes',
'alwaysRaised=yes',
'resizable=yes',
'scrollbars=yes',
'width=800',
'height=600'
].join( ',' );
document.getElementById( 'popup-1-button' ).onclick = function() {
// Note that config ID is passed in configId parameter
window.open( 'http://foxhills.localhost/admin/ckfinder/ckfinder.html?popup=1&configId=popup-1-config', 'CKFinderPopup1', popupWindowOptions );
};
在上面的代码中var file = evt.data.files.first(); 是我得到第一张图片的原因。我如何更改代码以获取所有 url 作为数组。
解决方案
对于您的活动,请尝试使用此测试
finder.on( 'files:choose', function( evt ) {
var files = evt.data.files;
var chosenFiles = '';
files.forEach( function( file, i ) {
chosenFiles += ( i + 1 ) + '. ' + file.get( 'name' ) + '\n';
} );
alert( chosenFiles );
} );
来源:https ://ckeditor.com/docs/ckfinder/ckfinder3/#!/api/CKFinder.Application-event-files_choose
推荐阅读
- r - 转置表以与 gt::gt() 一起使用
- sql - 如果字符之前存在空格,Laravel 就不会返回结果
- py2app - Objective-c 调用带有多个参数的 python 方法使用 py2app 和 pyobjc
- docker - YAML 与 Anchors ...如何结合?
- python - 在 Django 中的两个模板之间来回传递参数
- powerbi - 如何测试 PowerBI 计划刷新是否有效?
- java - 如何使用 JAVA 泛型避免代码冗余
- algorithm - 为什么堆排序时间复杂度在 CLRS 算法书中的 Big-Oh(N log N) 中给出,而不是在 Theta 中?
- mysql - 多产品套件的数据库设计
- mysql - 搞砸了 mysql-server 8.0 安装。如何修复或重新开始?