首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >filepicker.io中文件的顺序

filepicker.io中文件的顺序
EN

Stack Overflow用户
提问于 2014-09-17 22:24:35
回答 1查看 130关注 0票数 1

我们使用filepicker.io将多个文件加载到基于Ruby的web应用程序中。从filepicker.io返回的文件列表按照上传完成的顺序排列。是否有方法使返回的文件列表按照文件在filepicker.io接口中出现的顺序排列。我们正在努力防止用户感到困惑,并希望按照文件在filepicker.io界面中出现的顺序呈现给他们。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-30 08:55:24

Filepicker没有排序函数,但是由于得到了数组对象,所以可以按值对其进行排序。

本地文件通常按文件名排序。示例文件筛选器数组:

代码语言:javascript
复制
var blobArray = [
  {
    "url":"https://www.filepicker.io/api/file/tycOAXjbQU2DJR4WGhGl",
    "filename":"facebook_photo.jpg",
    "mimetype":"image/jpeg",
    "isWriteable":true
  },
  {
    "url":"https://www.filepicker.io/api/file/jOBXIKBQtukNEBJFDRjg",
    "filename":"2.jpg",
    "mimetype":"image/jpeg",
    "isWriteable":true},
  {
    "url":"https://www.filepicker.io/api/file/sjoVCCVTT3euKVpzBL5p",
    "filename":"xxx.jpg",
    "mimetype":"image/jpeg",
    "isWriteable":true
  },
  {
    "url":"https://www.filepicker.io/api/file/qATXanFXRjSkcG0onEee",
    "filename":"xx.jpg
    .jpg","mimetype":"image/jpeg","isWriteable":  true
  },
  {
    "url":"https://www.filepicker.io/api/file/KyAh8HNSoWZZOQeAs2mR",
    "filename":"3.jpg",
    "mimetype":"image/jpeg",
    "isWriteable":true
  },
  {
    "url":"https://www.filepicker.io/api/file/x3DpwRauDiAMEeZwj2wT",
    "filename":"4.png
    .jpg","mimetype":"image/jpeg",
    "isWriteable": true
  }
];

按文件名排序:

代码语言:javascript
复制
blobArray.sort(function(a, b){
 var filenameA = a.filename.toLowerCase(), 
   filenameB = b.filename.toLowerCase();

 if (filenameA < filenameB) //sort string ascending
   return -1 
 if (filenameA > filenameB)
   return 1
 return 0 //default return value (no sorting)
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25901303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档