我有一个objectId列表,我试图在另一个类中检索另一个列表,其中指针值等于当前parseObject的objectId。
我意识到我正在将字符串“objectId”与指针“threadPointer”进行比较,所以如果objectId等于threadPointer _Pointer值,有人可以帮我查询从类中检索项目列表
public void retrieveThreadListStoreInDB()
{
ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
query.include("postedBy");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
// Query is successful now lets load data from parse
ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
if (!isFinishing()) {
// TODO : Notify to refresh data
}
} else {
Log.d("DEBUG", "ERROR PINNING DATA WITH EXCEPTION : " + e);
}
}
});
}
}
});
}
public void retrievePostsListStoreInDB()
{
ParseQuery<ParseObject> query = ParseQuery.getQuery("Posts");
query.include("postedBy");
query.include("threadPointer");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(final List<ParseObject> list, ParseException e) {
if (e == null) {
// Query is successful now lets load data from parse
ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
if (!isFinishing()) {
// TODO : Notify to refresh data
Log.d("DEBUG: ","Finished retrieval");
Log.d("DEBUG", list.toString());
ParseObject object = (ParseObject)list.get(1).get("threadPointer");
Log.d("DEBUG_THREAD_POINTER", object.getObjectId());
}
} else {
Log.d("DEBUG", "ERROR PINNING DATA WITH EXCEPTION : " + e);
}
}
});
}
}
});
}
这是我从本地db检索ThreadList的地方
public void retrieveThreadList(){
List<ParseObject> parseObjectList = new ArrayList<ParseObject>();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
query.orderByDescending("updatedAt");
query.fromLocalDatastore();
// Data retrieval was successfull
try {
parseObjectList= query.find();
} catch (ParseException e) {
e.printStackTrace();
}
for (ParseObject parseObject : parseObjectList) {
String title = (String) parseObject.get("threadTitle");
ParseUser parseUser = (ParseUser) parseObject.get("postedBy");
String profilePictureUrl="local";
try {
profilePictureUrl = ((ParseFile) parseUser.get("profilePicture")).getUrl();
}catch (Exception exception)
{
Log.d("DEBUG_FB","profilePicture not retrieved");
}
String threadObjectId = parseObject.getObjectId();
Log.d("DEBUG_FB_THREAD_ID",threadObjectId);
ParseQuery parseQueryToRetrievePosts = ParseQuery.getQuery("Posts");
parseQueryToRetrievePosts.fromLocalDatastore();
//----****** NEED HELP HERE ******----
parseQueryToRetrievePosts.whereEqualTo("threadPointer",parseObject.getObjectId());
try {
List<ParseObject> postsList = parseQueryToRetrievePosts.find();
Log.d("DEBUG_FB_POSTS_LIST",postsList.toString());
} catch (ParseException e) {
e.printStackTrace();
}
/* To retrieve data over the network --- THIS WORKS WELL BUT I DONT WANT A NETWORK CALL
ParseRelation <ParseObject> posts = parseObject.getRelation("postMessage");
ParseQuery postsQuery = posts.getQuery();
List<ParseObject> postsList = new ArrayList();
try {
postsList=postsQuery.find();
for (ParseObject parseObject1: postsList)
{
String postMessage = (String)parseObject1.get("postMessage");
Log.d("DEBUG_FB_MSG", postMessage);
}
Log.d("DEBUG_FB_POSTS", postsList.toString());
}catch (Exception e)
{
}
*/
threadModelStore threadObject = new threadModelStore(title,profilePictureUrl);
Log.d("DEBUG_FB", profilePictureUrl);
Log.d("DEBUG_FB", title);
threadItemList.add(threadObject);
}
先生,我的情况是我有这些课程
- THREADS(Class),它有POSTS(与_POSTS的关系)类我想要检索特定线程的相关帖子。我无法确定 与本地数据存储的关系,如果有办法,请告诉我 这样做 ? - (UNSOLVED)
醇>
答案 0 :(得分:1)
ParseObject threadPointer=ParseObject.createWithoutData("Pointer_class_Name", "pointer_object_id");
ParseQuery<ParseObject> query=ParseQuery.getQuery("className");
query.whereEqualTo("_Pointer", threadPointer);
query.include("_Pointer");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> listCommunity, ParseException e) {
// TODO Auto-generated method stub
Log.d(TAG, "done");
if(e==null){
// access your data
}else{
// Error in retrieving data
}