(转)ueditor使用webuploader以后多图上传后顺序乱掉问题解决方法
2015-07-16 14:28
806 查看
原文网址:http://canlynet.iteye.com/blog/2155856
我上一个版本用的是ueditor1.3.6,自从1.4.2版以后,“前端上传模块统一改用webuploader”,ueditor在多图上传一直考虑漏掉了图片顺序的问题。
我的网站在用户上传图片文章的时候,使用多图上传,点确认后,编辑框内的图片顺序是乱的。
看webuploader的问题在于多线程上传,ueditor对“uploadSuccess”的处理是上传成功一张,就加入到数组中,这样如果图片上传完成顺序是乱的,最终加入文本框的顺序也乱了。
我这里修改了一下js,供大家参考,希望ueditor能改进这个问题:
vim dialogs/image/image.js
716 uploader.on('uploadSuccess', function (file, ret) {
717 var $file = $('#' + file.id);
718 try {
719 var responseText = (ret._raw || ret),
720 json = utils.str2json(responseText);
721 if (json.state == 'SUCCESS') {
722 _this.imageList[$file.index()] = json; // 按选择好的文件列表顺序存储
723 $file.append('');
724 } else {
725 $file.find('.error').text(json.state).show();
726 }
727 } catch (e) {
728 $file.find('.error').text(lang.errorServerUpload).show();
729 }
730 });
vim dialogs/attachment/attachment.js
500 uploader.on('uploadSuccess', function (file, ret) {
501 var $file = $('#' + file.id);
502 try {
503 var responseText = (ret._raw || ret),
504 json = utils.str2json(responseText);
505 if (json.state == 'SUCCESS') {
506 _this.fileList[$file.index()] = json;
507 $file.append('');
508 } else {
509 $file.find('.error').text(json.state).show();
510 }
511 } catch (e) {
512 $file.find('.error').text(lang.errorServerUpload).show();
513 }
514 });
vim dialogs/video/video.js
729 uploader.on('uploadSuccess', function (file, ret) {
730 var $file = $('#' + file.id);
731 try {
732 var responseText = (ret._raw || ret),
733 json = utils.str2json(responseText);
734 if (json.state == 'SUCCESS') {
735 uploadVideoList[$file.index()] = {
736 'url': json.url,
737 'type': json.type,
738 'original':json.original
739 };
740 $file.append('');
741 } else {
742 $file.find('.error').text(json.state).show();
743 }
744 } catch (e) {
745 $file.find('.error').text(lang.errorServerUpload).show();
746 }
747 });
如上,都使用了$file.index()作为数组下标,可以保证图片上传后顺序是按照用户选择图片以后,加入到预览窗口的顺序。
另外说一下:windows里选择图片用shift的时候连选,如果一开始选择1.jpg,然后按住shift选择10.jpg,结果这个10.jpg会在第一个,1~9.jpg反而在后面;需要先选择10.jpg,按住shift再选择1.jpg,这样图片顺序是1~10.jpg没错。有人能告诉原因和解决方法么?难道只能倒着连选?
相关文章推荐
- UI_UITabBarController
- 解决设置uiview的alpha属性后导致subviews页透明
- UILabel、UITextView自适应得到高度
- Android开发UI之动画侦听
- UIButton 上设置 self.imageView self.titleLabel
- Builder 建造者 (创建型)
- EasyUI datagird 排序 按数字类型的问题
- 玩转iOS 9的UIDynamics
- WPF standard ComboBox Items Source Change Issue
- Android中使用Handler机制更新UI的三种解决方案
- UITableViewCell中的imageView固定大小
- Android UI学习之RadioButton和RadioGroup
- (C#)使用队列(Queue)解决简单的并发问题
- Mac下的UI自动化测试 (四)
- iOS UILocalNotification 多个本地通知,怎么有区分的删除
- POJ 2299 Ultra-QuickSort 树状数组,归并排序
- iOS数组count操作(NSUInteger)的安全性
- 如何更好地限制一个UITextField的输入长度
- SAP GUI FOR HTML登陆 (转)
- Windows 10 build 10240预览版上手操作视频