简体   繁体   English

解析云代码获取指针

[英]Parse Cloud Code fetch pointer

I'm working on an app where I'd like to implement radial search. 我正在开发一个想要实现径向搜索的应用程序。 For this, I created a class on Parse called "UserLocation", where I save the users coordinates and a pointer to the "_User" Object. 为此,我在Parse上创建了一个名为“ UserLocation”的类,在其中保存了用户坐标和指向“ _User”对象的指针。 Now I'm working on a cloud code function to get some users within a radius. 现在,我正在开发云代码功能,以使某些用户处于一定范围内。 With the following code, I'm getting the near people but unfortunately only with a pointer, so I would need to fetch all those users on the device. 通过以下代码,我得到了近距离的人,但不幸的是,只有一个指针,所以我需要获取设备上的所有这些用户。 Is there a way to get the User-Objects from the cloud code instead of the pointer? 有没有办法从云代码而不是指针中获取用户对象?

Parse.Cloud.define('circum_search', function (request, response)
{
    var lat = request.params.lat;
    var lon = request.params.lon;
    var radius = request.params.radius;
    var query = new Parse.Query("UserLocation");
    query.withinKilometers("location", new Parse.GeoPoint(lat, lon), radius);
    query.find({
        success: function(locationObjects) {
            Parse.Object.fetchAllIfNeeded(locationObjects);   
            response.success(locationObjects);
        }
    });
});

The answer I get now is an array of objects like this: 我现在得到的答案是这样的对象数组:

 {
  "location": {
    "__type": "GeoPoint",
    "latitude": 47.3268966,
    "longitude": 8.542694
  },
  "user": {
    "__type": "Pointer",
    "className": "_User",
    "objectId": "ce9GRAzCF8"
  },
  "createdAt": "2018-02-01T17:08:07.078Z",
  "updatedAt": "2018-02-01T17:08:07.078Z",
  "ACL": {
    "d9db3aUdYU": {
      "read": true,
      "write": true
    },
    "*": {
      "read": true
    }
  },
  "objectId": "m3DmYfFv7I",
  "__type": "Object",
  "className": "UserLocation"
}

The Goal I have now is to replace the object for the key "user" with the real user-object, not the pointer. 我现在的目标是用真实的用户对象而不是指针替换键“ user”的对象。

FYI You can also use the include() method of queries with dot notation to also include the objects stored as pointers on an included object. 仅供参考,您还可以使用带有点符号的查询的include()方法来将存储为指针的对象也包含在包含的对象上。 Ie if ClassA has a pointer to ClassB has a pointer to ClassC, you can do this: 也就是说,如果ClassA有一个指向ClassB的指针有一个指向ClassC的指针,则可以这样做:

var query = new Parse.Query("ClassA");
query.include("classB").include("classB.classC");

Assuming the fields are named using lowercase classname. 假设使用小写的类名来命名字段。

Ok, finally there's a very simple solution but I had a long time to find it ;) just add 好的,最后有一个非常简单的解决方案,但是我花了很长时间才能找到它;)只需添加

query.include('user')

where user is the name of the field with the Pointer 其中user是带有指针的字段的名称

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

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