Java 在Android中从Parse.com检索指针数据
我试图从parse.com数据库中的指针中检索数据,从类用户中检索字段为“companyId”的指针Company(它从类Company获取Company objectId),以便在创建对象时将另一个名为Note的表中的数据添加到名为companyId的字段中 这是我的parse.com数据库: 类名:用户Java 在Android中从Parse.com检索指针数据,java,android,pointers,parse-platform,Java,Android,Pointers,Parse Platform,我试图从parse.com数据库中的指针中检索数据,从类用户中检索字段为“companyId”的指针Company(它从类Company获取Company objectId),以便在创建对象时将另一个名为Note的表中的数据添加到名为companyId的字段中 这是我的parse.com数据库: 类名:用户 objectId字符串| companyId指针公司|用户名字符串|密码字符串 类名:Note objectId字符串| companyId字符串|文本字符串 我一直在寻找解决方案,但没有找
objectId字符串| companyId指针公司|用户名字符串|密码字符串 类名:Note objectId字符串| companyId字符串|文本字符串 我一直在寻找解决方案,但没有找到任何人,因为我不知道如何检索companyId值,因为它是一个指针 提前感谢您的任何回复 编辑:问题已解决,下面是它对我的作用以及“bigdee94”解决问题的其他方法
谢谢 卡洛斯,你可以试试这个:-
根据文档,为了从指针列调用关系数据,可以使用include()方法。
例如:-
ParseQuery userQuery=ParseUser.getQuery();
userQuery.include(“公司ID”);
findInBackground(新的FindCallback(){
公共void done(列出对象,parsee异常){
如果(e==null){
//已成功检索用户对象
ParseObject companyIdObject=(ParseObject)objects.get(“companyObjectIdColumn”);
}否则{
Log.d(“对象”,“错误:+e.getMessage());
}
});
其中,
companyObjectIdColumn
是Company
表(类)中的objectId
列,objects
是查询到的对象列表附言:您可以将
ParseObject companyIdObject
设置为全局变量,这样您就可以从任何地方访问它。一位mate帮助了我,下面是我们如何解决它的:
Note n = new Note();
ParseUser user = ParseUser.getCurrentUser();
ParseObject userObj= user.getParseObject("companyId");
note.put("companyId", userObj.getObjectId().toString());
我发现有点棘手,好像你确实在尝试:
Note n = new Note();
ParseUser user = ParseUser.getCurrentUser();
user.getParseUser("companyId");
它不会给出字段中的数据,我相信您可以访问数据所在的内存
感谢您的时间,希望这能帮助更多的人!我已经创建了指针对象,并且很容易从中检索到。下面是代码
final ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("Loading ...");
progress.setCancelable(false);
progress.show();
ParseGeoPoint point = new ParseGeoPoint(l1, l2);
ParseUser user = ParseUser.getCurrentUser();
ParseObject shop = new ParseObject("ShopLocations");
shop.put("locationName", locname.getText().toString());
shop.put("pin", Integer.parseInt(setpin.getText().toString()) );
shop.put("location", point);
shop.put("menu", ParseUser.getCurrentUser()); // this is poniter object creation in User table
shop.put("business", ParseUser.getCurrentUser()); // this is another pointer
shop.put("userobjectId", user.getObjectId());
shop.saveInBackground();
shop.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
// TODO Auto-generated method stub
progress.dismiss();
if (e == null) {
Toast.makeText(Createloctaion.this, "success", Toast.LENGTH_SHORT).show();
// success
} else {
customToast(e.getMessage());
}
}
});
下面是检索指针对象的代码:
if(ParseUser.getCurrentUser()!=null){
ParseQuery=ParseQuery.getQuery(“ShopLocations”);
query.whereEqualTo(“菜单”,ParseUser.getCurrentUser());
query.whereEqualTo(“business”,ParseUser.getCurrentUser());
query.whereEqualTo(“userobjectId”,ParseUser.getCurrentUser().getObjectId());
findInBackground(新的FindCallback(){
公共void done(列表对象,parsee异常){
如果(e==null){
if(object.size()>0){
for(ParseObject用户:对象){
字符串chkbank=user.getString(“locationName”);
Toast.makeText(Dashboard.this,“+chkbank,Toast.LENGTH_SHORT).show();
}
}否则{
//处理异常
}
}否则{
Toast.makeText(Dashboard.this,“+e.getMessage(),Toast.LENGTH_SHORT.show();
}
}
});
}
bigdee94,感谢您的回复,但我发现了一个更简单的解决方案,如下所述。我相信它是可行的,但如果我对您的回答没有错,我将不得不进行另一次ParseQuery以从表公司获取objectId。即使有人想这样做可能会有所帮助。不@CarlosRomero,您只需调用objectId co即可像这样列到另一个ParseObject中,ParseObject companyIdObject=(ParseObject)objects.get(“CompanyObjectColumn”);
。虽然我没有尝试过,但我相信它在逻辑上是正确的。我很高兴你找到了一个更简单的解决方案。不需要强制转换parse对象,你可以使用objects.getParseObject(“”)
与您所拥有的相反
final ProgressDialog progress = new ProgressDialog(this);
progress.setMessage("Loading ...");
progress.setCancelable(false);
progress.show();
ParseGeoPoint point = new ParseGeoPoint(l1, l2);
ParseUser user = ParseUser.getCurrentUser();
ParseObject shop = new ParseObject("ShopLocations");
shop.put("locationName", locname.getText().toString());
shop.put("pin", Integer.parseInt(setpin.getText().toString()) );
shop.put("location", point);
shop.put("menu", ParseUser.getCurrentUser()); // this is poniter object creation in User table
shop.put("business", ParseUser.getCurrentUser()); // this is another pointer
shop.put("userobjectId", user.getObjectId());
shop.saveInBackground();
shop.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
// TODO Auto-generated method stub
progress.dismiss();
if (e == null) {
Toast.makeText(Createloctaion.this, "success", Toast.LENGTH_SHORT).show();
// success
} else {
customToast(e.getMessage());
}
}
});
if(ParseUser.getCurrentUser()!=null) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("ShopLocations");
query.whereEqualTo("menu", ParseUser.getCurrentUser());
query.whereEqualTo("business",ParseUser.getCurrentUser());
query.whereEqualTo("userobjectId",ParseUser.getCurrentUser().getObjectId());
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> object, ParseException e) {
if (e == null) {
if (object.size() > 0) {
for (ParseObject user : object) {
String chkbank = user.getString("locationName");
Toast.makeText(Dashboard.this, ""+chkbank, Toast.LENGTH_SHORT).show();
}
} else {
// Handle the exception
}
} else {
Toast.makeText(Dashboard.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}