在我的网站上,我调用解析数据库,它从类中获取数据并将其放入数组中。
直到几天前,它对我认为是按“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 Guide :
// 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");
根据您的情况,请将“score”替换为“num”
关于javascript - 如何根据数字列从解析中排序数据数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19286868/