我想检查 Cloud Code 查询响应是否为 null 或为空。如果查询找到某些内容,则代码将起作用。当没有与查询匹配的对象时,我无法处理它。我该怎么办?
Parse.Cloud.define("testing", function(request, response) {
var queryCheckRepeatedPost = new Parse.Query("Update");
queryCheckRepeatedPost.equalTo("updateValid", true);
queryCheckRepeatedPost.first({
useMasterKey: true,
success: function(repeatedPost) {
//Sometimes query return an object
//Sometimes there are no objects to return
},
error: function() {
response.error("Error 01");
}
});
});
我尝试过:
Object.keys(repeatedPost).length === 0
var value = results[0].get("objectId");
if (value == null){
}
但是它们都不起作用。
最佳答案
我找到了答案。当查询返回空对象时,它是未定义的。
if (repeatedPost != undefined){
//The object is not empty
}else{
//the object is empty
}
关于javascript - 如何检查查询响应是否为空 Parse Sever?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46370636/