这是不可能根据链路接收对象 [英] It is impossible to receive object according to the link

查看:149
本文介绍了这是不可能根据链路接收对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建对象的文档中指定,我填补他们的属性并保存在数据存储中的链接:

As specified in the documentation I create objects, I fill their properties and save the link in the Data Store:

public class InvitationEntity extends GenericJson {
    @Key
    public String objectId;
    @Key
    public int status;
    @Key("_id")
    public String id;
    @Key
    public String name;
}
public class EventEntity extends GenericJson {
    @Key
    public String name;
    @Key
    public String eventDate;
    @Key
    public String location;
    @Key
    public String tip;
    @Key
    public KinveyReference invitations;

    public void initReference(InvitationEntity myInvitation){
        KinveyReference reference = new KinveyReference("invitationCollection", myInvitation.get("_id").toString());
        this.invitations = reference;
    }
}

...

 InvitationEntity invitationEntity = new InvitationEntity();
 invitationEntity.name = "3";
 invitationEntity.objectId="3";
mKinveyClient.appData("invitationCollection", InvitationEntity.class).save(invitationEntity, new KinveyClientCallback<InvitationEntity>() {
                @Override
                public void onSuccess(InvitationEntity invitationEntity1) {
                    Log.e("my", "Ok1 " + invitationEntity1.toString());

                    EventEntity eventEntity = new EventEntity();
                    eventEntity.tip = "33";
                    eventEntity.initReference(invitationEntity1);
                    mKinveyClient.appData("eventCollection", EventEntity.class).save(eventEntity, new KinveyClientCallback<EventEntity>() {
                        @Override
                        public void onSuccess(EventEntity eventEntity_rez) {
                            Log.e("my", "Ok2 " + eventEntity_rez.toString());
                        }

                        @Override
                        public void onFailure(Throwable t) {
                            Log.e("my", "Failed to save entity " + t.getMessage());
                        }
                    });
                }

                @Override
                public void onFailure(Throwable t) {
                    Log.e("my", "Failed to save entity " + t.getMessage());
                }
            });

现在我的要求:

    Query q = mKinveyClient.query();
    mKinveyClient.appData("eventCollection", EventEntity .class).get(q, new KinveyListCallback<EventEntity >() {
        @Override
        public void onSuccess(EventEntity [] resalt) {
                Log.d("my", resalt[0].toString());
        }

        @Override
        public void onFailure(Throwable t) {
            Log.d("my", "Error fetching data: " + t.getMessage());
        }
    });

我得到的结果:

{"invitations":{"_collection":"invitationCollection",
                            "_id":"52715e5b13dde23677021c80",
                            "_type":"KinveyRef"},
"tip":"33",
"_acl":{"creator":"526182566bbfcbf429000518"},
"_kmd":{"lmt":"2013-10-30T19:30:36.086Z",
                 "ect":"2013-10-30T19:30:36.086Z"},
"_id":"52715e5c13dde23677021c81",
"kid":"kid_TTpvqRShiO",
"collection":"eventCollection"}

和这将是理想的是接收

{"invitations":{"_id":"52715e5b13dde23677021c80",
                             "name":"3",
                             "objectId":"3",
                             "status":0,
                             "_acl":{"creator":"526182566bbfcbf429000518"},
                             "_kmd":{"lmt":"2013-10-30T19:30:35.912Z",
                                               "ect":"2013-10-30T19:30:35.912Z"},
                                               "kid":"kid_TTpvqRShiO",
                                               "collection":"invitationCollection"},
"tip":"33",
"_acl":{"creator":"526182566bbfcbf429000518"},
"_kmd":{"lmt":"2013-10-30T19:30:36.086Z",
                 "ect":"2013-10-30T19:30:36.086Z"},
"_id":"52715e5c13dde23677021c81",
"kid":"kid_TTpvqRShiO",
"collection":"eventCollection"}

如何接收对象因此而不是在它的链接,有其他的对象?

How to receive object so that instead of the link in it there was other object?

推荐答案

我在Kinvey一名工程师,可以帮助您与this--我张贴在我们的支持论坛,但想通,别人可能会在这里绊倒:

I'm an engineer at Kinvey, and can help you out with this-- I posted the same answer on our support forums, but figured that someone else might stumble upon it here:

这不是不可能的!

在应用程序数据中,有的Get和GetEntity方法的多种变体。看看这里的javadoc:<一href=\"http://devcenter.kinvey.com/android/reference/api/reference/com/kinvey/android/AsyncAppData.html\" rel=\"nofollow\">http://devcenter.kinvey.com/android/reference/api/reference/com/kinvey/android/AsyncAppData.html

On Appdata, there are multiple variations of the Get and GetEntity methods. Check out the javadocs here: http://devcenter.kinvey.com/android/reference/api/reference/com/kinvey/android/AsyncAppData.html

要解决KinveyReferences,传递的String []包含要解决的第二个参数的get方法字段的名称,你的情况,你要使用:

To resolve KinveyReferences, pass a String[] containing the names of the fields you wish to resolve as the second parameter to the get method, in your case you want to use:

mKinveyClient.appData("eventCollection", EventEntity .class).get(q, new String[]{"invitations"}, new KinveyListCallback() { ... }

现在,该回调的onSuccess将返回EventEntity,但引用解决,您可以拨打:

Now, the onSuccess callback will return an EventEntity, but the references are resolved and you can call:

InvitationEntity myInvite = results[0].getInvitations.getTypedObject(InvitationEntity.class);

这篇关于这是不可能根据链路接收对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆