2017-09-14 37 views
0

這是一個關於Firebase.Xamarin NuGet包的問題。我正在使用聲明await Client.Child(FirebaseKeys.Users).OrderBy("FirstName").OnceAsync<object>();按名排序用戶,但我沒有按排序順序獲取用戶。在源代碼中有一條評論指出:「這主要用於跟蹤過濾查詢,並且由於實現了firebase,數據實際上可能不會被排序。」我不確定是否可以對數據進行分類。Firebase.Xamarin的OrderBy()方法不對數據進行排序

+1

如果您無法通過Firebase訂購您的結果,您可以始終將查詢實現爲「列表」或適當的結構,然後在內存中對其進行排序。 –

+0

當你從'對象'獲取數據時,你可能會撤銷順序。您需要遍歷[DataSnapshot.Children](https://firebase.google.com/docs/reference/unity/class/firebase/database/data-snapshot#children)或[偵聽兒童事件[( https://firebase.google.com/docs/database/unity/retrieve-data#child-events)來維護訂單。 –

回答

0

如果你看一下Firebase.Xamarin Github上的代碼,它明確了方法的文檔中指出這樣:

 /// <summary> 
     /// Order data by given <see cref="propertyName"/>. Note that this is used mainly for following filtering queries and due to firebase implementation 
     /// the data may actually not be ordered. 
     /// </summary> 
     /// <param name="child"> The child. </param> 
     /// <param name="propertyName"> The property name. </param> 
     /// <returns> The <see cref="OrderQuery"/>. </returns> 
     public static OrderQuery OrderBy(this ChildQuery child, string propertyName) 
     { 
      return child.OrderBy(() => propertyName); 
     } 

實際上,數據可能不會可根據用戶需要進行排序。

+0

它已經在問題中提到過。 – puck

+0

當然,你是對的。 SO的移動視圖有點困難。我沒有正確閱讀。我將在沒有編輯或刪除的情況下離開我的答案,以便其他人可以閱讀,因爲我發佈了實際的源代碼和文檔。感謝您指出! –

相關問題