簡體   English   中英

Parse.com通過查詢獲得價值

[英]Parse.com get value with query

我一直在尋找一個如何使用Parse.com查詢的例子。 它真的很模糊。 我認為應該從:

ParseQuery query=ParseQuery.getQuery(<Class(aka table name)>);

但后來,我不知道。 你可以做點什么

query.whereEqualsTo(<collumn>,value)

在那種情況下,如果它存在,我會得到'價值'。 我想做的是。 我有一個帶有列ID和名稱的表。 我知道ID是什么,它是0.所以現在我想知道Name屬於ID = 0但是我應該使用什么查詢,我不知道......

Parse的Android指南在這里有一個基本的查詢示例,它將返回與您的約束匹配的第一個對象:

ParseQuery<ParseObject> query = ParseQuery.getQuery("YourClassName");
query.whereEqualTo("ID", "someID");
query.getFirstInBackground(new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (object == null) {
      Log.d("score", "The getFirst request failed.");
    } else {
      Log.d("score", "Retrieved the object.");
    }
  }
});

我不建議使用getFirstInBackground來獲取查詢,使用findInBackGround然后過濾您正在尋找的值要好得多。

要查找用戶名以abc開頭的用戶列表,您可以使用該條件

query.whereStartsWith("username", "abc");

所以整個查詢看起來像

ParseQuery<ParseObject> query = ParseQuery.getQuery("YourClassName");
query.whereStartsWith("username", "abc");
query.findInBackground(new FindCallback<ParseObject>() {
  public void done(List<ParseObject> object, ParseException e) {
    if (object == null) {
      Log.d("score", "The getFirst request failed.");
    } else {
      Log.d("score", "Retrieved the object.");
    }
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM