如何检索 parseObject 子类的指针 [PARSE SERVER]

Posted

技术标签:

【中文标题】如何检索 parseObject 子类的指针 [PARSE SERVER]【英文标题】:How to retrieve a pointer of parseObject subclasses [PARSE SERVER] 【发布时间】:2018-12-10 23:47:05 【问题描述】:

我想使用子类,但我遇到了一些问题。该文档没有明确说明如何使用子类检索解析服务器上可用的所有数据类型。

这是我的 objOwnFeeds

@ParseClassName(ParseIdentifier.ownFeedsClass)

public class objOwnFeeds  extends ParseObject 
    //starter fields
    public String getObjectId() 
        return getString(ParseIdentifier.getObjectIdField());
    
    public ParseACL getAcl() 
        return getACL();
    
    public void setAcl(ParseACL acl) 
        setACL(acl);
    
    public Date getCreatedAt() 
        return getCreatedAt();
    
    public void setCreatedAt(Date date) 
        setCreatedAt(date);
    



    //extended fields

      //Strings
        public String getOwnerId() 
            return getString(ParseIdentifier.getOwnerId());
        
        public String getUserInfoId() return getString(ParseIdentifier.getUserInfoId());
        public String getFeedId() return getString(ParseIdentifier.getFeedId());
        public String getType() return getString(ParseIdentifier.getType());


      //Booleans
      public Boolean isCreatedByMe() return getBoolean(ParseIdentifier.getCreatedByMe());
      public Boolean canNotification() return getBoolean(ParseIdentifier.getCanNotification());
      public Boolean isLikedByMe() return getBoolean(ParseIdentifier.getLikedByMe());
      public Boolean isFollowedByMe() return getBoolean(ParseIdentifier.getFollowedByMe());

      //Parse Objects  the problem is here!
     public objFeed getFeed() return (objFeed) getParseObject(ParseIdentifier.getFeed());


      //numbers
      public int getIntervalNotification() return getInt(ParseIdentifier.getIntervalNotification());
      public long getLastNotificationSent() return getLong(ParseIdentifier.getLastNotificationSent());


寻找getFeed()

@ParseClassName(ParseIdentifier.feedsClass)

public class objFeed extends ParseObject 

public String getObjectId() 
    return getString(ParseIdentifier.getObjectIdField());



public String getNome() 
    return getString(ParseIdentifier.nomeFeedField);


public void setNome(String nome) 
    put(ParseIdentifier.nomeFeedField, nome);



public String getNomeToLowerCase() 
    return getString(ParseIdentifier.nomeToLowerCaseFeedField);


public void setNomeToLowerCase(String nomeToLowerCase) 
    put(ParseIdentifier.nomeToLowerCaseFeedField, nomeToLowerCase);



public String getUsers() 
    return getString(ParseIdentifier.usersFeedField);


public void setUsers(String users) 
    put(ParseIdentifier.usersFeedField, users);


public int getTotalLikes() 
    return getInt(ParseIdentifier.totalLikesFeedField);

public void setTotalLikes(int totalLikes) 
    put(ParseIdentifier.totalLikesFeedField, totalLikes);


public int getgetRankPosition() 
    return getInt(ParseIdentifier.rankPosition);

public void setRankPosition(int rankPosition) 
    put(ParseIdentifier.rankPosition, rankPosition);


public int getTotalFollowers() 
    return getInt(ParseIdentifier.totalFollowersFeedField);


public void setTotalFollowers(int totalFollowers) 
    put(ParseIdentifier.totalFollowersFeedField, totalFollowers);


public ParseACL getAcl() 
    return getACL();


public void setAcl(ParseACL acl) 
    setACL(acl);


public String getUserId() 
    return getString(ParseIdentifier.userIdFeedField);


public void setUserId(String userId) 
    put(ParseIdentifier.userIdFeedField, userId);


public Date getCreatedAt() 
    return getCreatedAt();


public void setCreatedAt(Date date) 
    setCreatedAt(date);


public String getUrlFeed() 
    return getString(ParseIdentifier.urlFeedFeedField);


public void setUrlFeed(String urlFeed) 
    put(ParseIdentifier.urlFeedFeedField, urlFeed);


public ParseUser getCreatedBy() 
    return getParseUser(ParseIdentifier.createdByField);


public void setCreatedBy(ParseUser user) 
    put(ParseIdentifier.createdByField, user);


您可以在此处查看如何查看这些对象:此图像指的是 objOwnFeeds

我也有。

ParseObject.registerSubclass(objFeed.class);
ParseObject.registerSubclass(objOwnFeeds.class);

这是我的查询:

ParseQuery query = new ParseQuery(objOwnFeeds.class);
query.include("Feed");
query.findInBackground(new FindCallback<objOwnFeeds>() 
    @Override
    public void done(List<objOwnFeeds> objects, ParseException e) 
        if (e == null)

            for (objOwnFeeds obj : objects) 
                Log.i("xxxzdae", "done: " + obj.getFeed().getObjectId());

            
        
    

);

getFeed() 总是返回 null。 感谢您的关注。

【问题讨论】:

【参考方案1】:
public objFeed getFeed()  return ParseObject.createWithoutData(objFeed.class, getParseObject(ParseIdentifier.getFeed()).getObjectId(); 

在您从中检索任何数据之前,不要忘记致电object.fetchIfNeeded()

【讨论】:

以上是关于如何检索 parseObject 子类的指针 [PARSE SERVER]的主要内容,如果未能解决你的问题,请参考以下文章

无法创建指向未保存 ParseObject 的指针

从 ParseObject 中检索 ParseFile - Android C# Xamarin Parse

在用户类中查询 ParseObject(Pointer)

一个c++虚函数与this指针的问题

如何从 Parse.com 检索数组

子类指针转换成父类指针时,指针值会变化