按字段从 Parse (.com) 查询结果中获取特定对象,而无需返回数据库

Get specific object from Parse (.com) query result by field without going back to DB

假设我对 Parse 数据库进行查询并获得一个结果对象,每个结果都有一个字段 place_id

然后我如何通过 place_id 从结果中获取特定对象而不实际返回数据库(想要最小化网络流量和数据库查询...)?

我的查询如下所示:

var LatestUpdate = Parse.Object.extend("LatestUpdate");
var query = new Parse.Query(LatestUpdate);
query.containedIn("place_id", arrayOfplaceIds);
query.find().then(
  function(results){
    // and then i want to do something like:
    return results.findByField("place_id", 1234) // get a specific object from the result without going back to the database?
  }
);

您必须遍历结果并找到符合条件的对象。您可以使用云端支持的 underscore.js 轻松完成此操作:

var match = _.find(results, function(object){ return object.get("place_id") == 1234; });

只需确保您的 js 文件顶部有 var _ = require('underscore');