2013-10-10 35 views
0

在我的網站上,我打電話給我的分析數據庫,它從一個類中獲取數據並將其放入數組中。如何根據數字列從一個Parse中訂購數據

直到幾天前,它通過'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」(底部)。

感謝任何能夠幫助的人!

+0

這有什麼做用JavaScript但SQL。你需要在你的sql語句中定義返回數據的順序,例如SELECT * FROM table ORDER BY num; – jeff

+0

Parse.com不使用SQL,它使用MongoDB。要與它進行交互,請使用他們的JavaScript庫(如問題代碼塊中的查詢所示)。 –

+0

@jeff丹尼爾的回答完美無瑕。 – javinladish

回答

2

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"); 

在你的情況下,更換 '得分' 與 '民'

+0

非常感謝。我所要做的就是從字面上添加這條線,並修復它! – javinladish

+0

以隨機順序顯示查詢數據怎麼辦? – drearypanoramic