如何根据数字列从 Parse 中对数据数组进行排序

How do I order an array of data from a Parse, based on a number column

本文关键字:数据 数组 排序 Parse 何根 数字      更新时间:2023-09-26

在我的网站上,我调用我的解析数据库,它从一个类中获取数据并将其放入数组中。

直到几天前,它还对数据进行了排序,我认为这是按"createdAt"时间戳排序的。但是现在它似乎在数组中随机向上/向下移动几列,我不知道为什么。

我在类中还有另一列标题为"num",仅用于对每一行进行编号。

目前,调用数据库以获取数据的代码如下所示:

// Query the content class for rows where the image exists
var content = Parse.Object.extend("content");
var query = new Parse.Query(content);
query.exists("image");
query.find({
  success: function(results) {
    // If the query is successful, store each image URL in an array of image URL's
    var grid = $("#grid"), slider = $("#slider"), mainContent = $("#main_content"), initialImages, moreImages, totalLoadedImg = 0, remainingImages = results.length;

有没有办法在调用数据库时,它会根据数据库中的"num"列按顺序将数据存储在数组中?

这是网站的链接:http://colorperday.com

每种颜色都有自己的列,该列也有自己的数字"num"。我正在尝试做的是将颜色从最高的"num"(顶部(到最低的"num"(底部(排序。

感谢任何能够提供帮助的人!

来自 Parse.com JavaScript 指南:

// Sorts the results in ascending order by the score field
query.ascending("score");
// Sorts the results in descending order by the score field
query.descending("score");

在您的情况下,将"分数"替换为"数字">