如何从类关系中检索对象列表
How can I retrieve a list of objects from a class relation?
我有一个类Store
,它有一个包含Parse上多个Item
对象的关系itemsInStore
。我目前正在尝试解析云代码以检索Store
中的所有Items
,但不知道这方面的常见做法是什么
特别是,我在这里找不到真正回答我问题的文章,例如查询应该如何
Parse.Cloud.define("retrieveNearbyLocationsAndItemsWithCurrentLocation", function(request, response) {
var Store = Parse.Object.extend("Store");
var store = new Store();
var query = new Parse.Query(Store);
var userGeoPoint = new Parse.GeoPoint(request.params.lat, request.params.long);
query.near("geopoint", userGeoPoint);
query.limit(1);
query.find({
success: function(httpResponse) {
response.success(httpResponse[0].get("itemsInStore"));
console.log(httpResponse[0].get("itemsInStore"));
},
error: function(httpResponse) {
response.error("Error: retrieveNearbyLocationsAndItemsWithCurrentLocation");
}
});
});
控制台日志将返回{"__type":"Relation","className":"Item"}
为了深入研究这个Relation
并检索其中的所有Item
对象,接下来应该做什么?
关系回答查询。运行该查询以获取相关元素。
Parse.Cloud.define("retrieveNearbyLocationsAndItemsWithCurrentLocation", function(request, response) {
var Store = Parse.Object.extend("Store");
var store = new Store();
var query = new Parse.Query(Store);
var userGeoPoint = new Parse.GeoPoint(request.params.lat, request.params.long);
query.near("geopoint", userGeoPoint);
query.limit(1);
query.find().then(function(stores) {
if (stores.length && stores[0].relation("itemsInStore")) {
var itemQuery = stores[0].relation("itemsInStore").query();
return itemQuery.find();
} else {
return [];
}
}).then(function(items) {
response.success(items);
}, function(error) {
response.error(error);
});
});
相关文章:
- 如何从类关系中检索对象列表
- 检索对象项的路径
- 正在根据ID从数组中检索对象
- 以文本形式检索对象元素中的SVG Dom
- AJAX来检索对象并将其存储在变量中
- 如何在帮助程序或事件中检索对象的内部_id
- 如何在 ydn-db 中检索对象的排序列表
- Javascript - 检索对象属性路径
- 从具有特定参数的数组中检索对象
- 如何从jsonString中检索对象
- 检索对象自己的标记
- 从URL检索对象/资源
- 如何从Google Apps脚本项目属性中存储和检索对象
- 如何从GTM数据层中检索对象
- JQueryAJAX检索对象数组
- 正在检索对象中嵌套的值
- 使用PHP从JSON中检索对象
- 如何从具有给定(键、值)对的长列表中检索对象
- 使用承诺从 mongo db 检索对象时出错
- 在树状的angularjs模型中检索对象