PARSE.COM:在查询时获取数据

时间:2017-06-05 11:28:14

标签: android parse-platform

在Parse中进行查询时,仅下载ObjectId

有没有办法在同一个电话中下载所有列数据?

如果没有,这是获取它的最快方式吗?

这就是我提出的,但由于调用是一个接一个地完成的,所以执行它需要很长时间。

// Create query
ParseUser user = ParseUser.getCurrentUser();
ParseQuery<Centro> query = ParseQuery.getQuery("...");
query.include(...);
query.whereEqualTo(...);
query.addAscendingOrder(...);

// Execute query
try {
    CLASS = query.find();
} catch (ParseException e) {
    return false;
}

// Force to fetch all data by reading a single column
for (CLASS class : classes){
    try {
        class.fetch();
        class.getSomething();
    } catch (ParseException e) { }
}

感谢任何帮助,谢谢。

2 个答案:

答案 0 :(得分:0)

我不认为只要获得objectID,如果您在文档中构建查询,那么你可以得到这样的东西:

ParseQuery<ParseObject> query = ParseQuery.getQuery("FamousPerson");
query.whereEqualTo("name", "Donald Trump");
query.getFirstInBackground(new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (object == null) {
      Log.d("person", "The getFirst request failed.");
    } else {
       String myJob = object.getString("Job") //equals "President"

    }
  }
});

答案 1 :(得分:0)

include函数用于告诉Parse也检索其他表的内容。我以为我必须在那里输入表名,但是,我必须输入字段名称。

如果有人感兴趣,请关联文档:http://docs.parseplatform.org/android/guide/

我在下面的示例中意识到,由于Comment(表名)是大写的,而行query.include("post")以小写形式指定post,因此它必须是字段名。

ParseQuery<ParseObject> query = ParseQuery.getQuery("Comment");

// Retrieve the most recent ones
query.orderByDescending("createdAt");

// Only retrieve the last ten
query.setLimit(10);

// Include the post data with each comment
query.include("post");

query.findInBackground(new FindCallback<ParseObject>() {
  public void done(List<ParseObject> commentList, ParseException e) {
    // commentList now contains the last ten comments, and the "post"
    // field has been populated. For example:
    for (ParseObject comment : commentList) {
      // This does not require a network access.
      ParseObject post = comment.getParseObject("post");
      Log.d("post", "retrieved a related post");
    }
  }
});