假设我对 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');
即可。
关于javascript - 从 Parse (.com) 查询结果中按字段获取特定对象,无需返回 DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34628795/