我们使用filepicker.io将多个文件加载到基于Ruby的web应用程序中。从filepicker.io返回的文件列表按照上传完成的顺序排列。是否有方法使返回的文件列表按照文件在filepicker.io接口中出现的顺序排列。我们正在努力防止用户感到困惑,并希望按照文件在filepicker.io界面中出现的顺序呈现给他们。
发布于 2014-09-30 08:55:24
Filepicker没有排序函数,但是由于得到了数组对象,所以可以按值对其进行排序。
本地文件通常按文件名排序。示例文件筛选器数组:
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
}
];按文件名排序:
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)
});https://stackoverflow.com/questions/25901303
复制相似问题