我有一个云函数,它循环一个名为drives
. 此类中的每个元素都有一个数组,其中包含指向名为 的类的指针driveResults
。
我做了一个云作业来获取这样的驱动器:
首先,我创建了一个名为 fetchPaginated 的函数,因此我可以通过 1 次调用获取 1000 多个项目。
Parse.Collection.prototype.fetchPaginated = function(callbacks){
var promise = new Parse.Promise();
var result = [];
var thisCol = this;
var processCallback = function(res) {
result = result.concat(res);
if (res.length === thisCol.query._limit) {
process(res[res.length-1].id);
}else{
thisCol.reset(result);
delete thisCol.query._where.objectId;
if(callbacks && callbacks.success)
callbacks.success();
promise.resolve(true);
}
}
var process = function(skip) {
if (skip) {
thisCol.query.greaterThan("objectId", skip);
}
thisCol.query.ascending("objectId");
thisCol.query.find().then(function querySuccess(res) {
processCallback(res);
}, function queryFailed(reason) {
if(callbacks && callbacks.error)
callbacks.error(thisCol, reason);
promise.reject("query unsuccessful, length of result " + result.length + ", error:" + reason.code + " " + reason.message);
});
}
process(false);
return promise;
};
其次,我为驱动器创建模型、查询和集合。
// ---------------------------------------------------------------------------------- Drives
// --------------------------------------------------- MODEL
var DrivesModel = Parse.Object.extend({
className: "Drives",
});
exports.DrivesModel = DrivesModel;
// --------------------------------------------------- QUERY
var DrivesQuery = new Parse.Query(DrivesModel);
exports.DrivesQuery = DrivesQuery;
DrivesQuery.limit(1000);
DrivesQuery.addAscending('date');
DrivesQuery.include('driveResults');
DrivesQuery.find({
success: function(results) {
// results is an array of Parse.Object.
},
error: function(error) {
// error is an instance of Parse.Error.
}
});
// --------------------------------------------------- COLLECTION
var DrivesCollection = Parse.Collection.extend({
model: DrivesModel,
query: DrivesQuery,
});
exports.DrivesCollection = DrivesCollection;
var drivesCollection = new DrivesCollection();
exports.drivesCollection = drivesCollection;
然后,在我的云函数里面的一个promise中,我有这个:
// some initializing code here...
return iEVCollections.drivesCollection.fetchPaginated();
}).then(function(){
// at this point, all drives have been fetched.
// some code here.
如您所见,DrivesQuery 包括 driveResults。
问题是:数组 driveResuls 包含null
. 如果我将它打印到控制台,这是数组的一部分:
[null,{"A Valid":"Object"},null,null,{"A Valid":"Object"},null,{"A Valid":"Object"},{"A Valid":"Object"},null,,null,null,{"A Valid":"Object"}]
在数据浏览器中,我可以看到这个数组里面绝对没有 null,当我在骨干应用程序上做同样的事情时,它只包含有效的整体。那么为什么我的云功能缺少这些元素呢?
谢谢你的帮助。