简体   繁体   English

解析:如何获取没有ID的固定对象

[英]Parse: how to get pinned object without id

Ive got application on android which should work without internet and with parse database when internet is on. 我已经在android上运行了应用程序,该应用程序可以在没有互联网的情况下正常工作,并且在互联网开启时可以解析数据库。 Also I faced with problem of getting of pinned ParseObject which not saved in online database before. 我也遇到了以前没有保存在在线数据库中的固定ParseObject的问题。

So what I do: 所以我要做的是:

ParseObject car = new ParseObject("cat");
cat.put("name","Pussy");
cat.pinInBackground();

So, now I want to get this cat by query with query.getInBackground but, I cant do it because I haven't objectId, which automatically generated only after saving in online database. 因此,现在我想通过使用query.getInBackground进行查询来获得这只猫,但是,由于我没有objectId(仅在保存在线数据库后才自动生成),所以我无法做到这一点。

You can search for cats (objects) with given properties in the local datastore: 您可以在本地数据存储区中搜索具有给定属性的猫(对象):

ParseQuery<ParseObject> query = ParseQuery.getQuery("cat");
query.fromLocalDatastore();
query.whereEqualTo("name", "Pussy");
query.findInBackground(new FindCallback<ParseObject>() {
    public void done(List<ParseObject> catList, ParseException e) {
        if (e == null) {
            Log.d("cat", "Retrieved " + catList.size() + " cats");
        } else {
            Log.d("cat", "Error: " + e.getMessage());
        }
    }
});

However, if name is the only property, you'll likely get a list of objects with more than one entry. 但是,如果name是唯一的属性,则可能会获得包含多个条目的对象列表。 Here, you may add other properties (eg an owner) to limit the number of possible matches. 在这里,您可以添加其他属性(例如所有者)以限制可能的匹配数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM