我想写一个Parse.com云代码函数来完成以下工作流程分支:解析云代码:逻辑在承诺
- 用户提交的值。
- 云代码函数检查该值是否与
code
类型的任何对象匹配。 - 如果不是,则该函数返回“not found”值。
- 如果是这样,
code
类型的对象被假定为具有指向item
类型对象的指针。 - 然后,检查
code.item
以查看它是否具有指向alert
类型对象的指针。 - 如果不是,则该函数返回“not found”值。
- 如果
code.item.alert
确实存在,那么我想获取完整的alert
对象,包括可能存在或不存在的指针,最多2层深。
当我开始写代码这个功能,我可以得到它的工作,以检查看code
是否存在的点,如果是这样,code.item.alert
是否也存在。
这是问题出现的地方。就目前而言,在我的函数的工作版本中,返回的alert
项只是类类型和objectId。我明白为什么会发生这种情况,并且我正在尝试编写代码来在返回对象之前填充对象,但是我没有做到这一点。
下面是工作,到目前为止(但只返回alert
对象的shell)代码:
Parse.Cloud.define("alertLookup", function (request, response) {
Parse.Cloud.useMasterKey();
var codeQuery = new Parse.Query("code");
codeQuery.equalTo("value", request.params.code);
codeQuery.include("item");
codeQuery.find().then(function (codes) {
if (codes.length === 0) {
response.success("no item");
} else {
var code = codes[0];
var item = code.get("item");
var alert = item.get("alert");
if (alert === null || alert === undefined) {
response.success("no item");
} else {
response.success(alert);
}
}
}, function (error) {
response.error(error);
});
});
这是我已尝试与141错误代码失败:
Parse.Cloud.define("alertLookup", function (request, response) {
Parse.Cloud.useMasterKey();
var codeQuery = new Parse.Query("code");
codeQuery.equalTo("value", request.params.code);
codeQuery.include("item");
codeQuery.find().then(function (codes) {
if (codes.length === 0) {
response.success("no item");
} else {
var code = codes[0];
var item = code.get("item");
var alert = item.get("alert");
if (alert === null || alert === undefined) {
response.success("no item");
} else {
return alert.fetch();
}
}
}).then(function (a) {
response.success(a);
}, function (error) {
response.error(error);
});
});
为什么fetch()
电话不能正常工作?当我插入console.log()
语句时,虽然alert
非空,但return alert.fetch();
似乎不会被调用。至少,response.success(a);
行永远不会被调用。为什么不?
的就是你得到的141错误信息? –
“未定义”。而已。 – mbm29414