Parse platform 云解析中未定义错误的索引

Parse platform 云解析中未定义错误的索引,parse-platform,cloud,Parse Platform,Cloud,正在云下函数中获取错误 NSMutableDictionary * params = [NSMutableDictionary new]; params[@"user"] = _sender_ID; params[@"recipientId"] = _owner_ID; params[@"message"] = msgToSend; [PFCloud callFunctionInBackground:@"sendPushToUser" withParameter

正在云下函数中获取错误

NSMutableDictionary * params = [NSMutableDictionary new];

    params[@"user"] = _sender_ID;
    params[@"recipientId"] = _owner_ID;
    params[@"message"] = msgToSend;
    [PFCloud callFunctionInBackground:@"sendPushToUser" withParameters:params block:^(id object, NSError *error) {
        if (!error) {
            // Push sent successfully

            NSLog(@"msg posted!");
        }
    }];
错误:

Error: TypeError: Cannot call method 'indexOf' of undefined
at main.js:15:35 (Code: 141, Version: 1.2.20)
main.js的代码如下

Parse.Cloud.define("sendPushToUser", function(request, response) {
var senderUser = request.user;
var recipientUserId = request.params.recipientId;
var message = request.params.message;

// Validate that the sender is allowed to send to the recipient.
 // For example each user has an array of objectIds of friends
 if (senderUser.get("friendIds").indexOf(recipientUserId) === -1) {
response.error("The recipient is not the sender's friend, cannot send push.");
}

   // Validate the message text.
   // For example make sure it is under 140 characters
   if (message.length > 140) {
  // Truncate and add a ...
message = message.substring(0, 137) + "...";
  }

// Send the push.
// Find devices associated with the recipient user
var recipientUser = new Parse.User();
recipientUser.id = recipientUserId;
var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.equalTo("user", recipientUser);

// Send the push notification to results of the query
Parse.Push.send({
where: pushQuery,
data: {
  alert: message
    }
  }).then(function() {
  response.success("Push was sent successfully.")
  }, function(error) {
  response.error("Push failed to send with error: " + error.message);
  });
});
上面是在main.js中编写的代码,在下面的链接中得到了相同的代码。据我从错误中了解,问题在于FriendID,这就是为什么它不调用方法'indexOf'


从这个链接中得到了这个想法

与评论中的断言相反,senderUser即request.user实际上没有在FriendID中存储朋友数组

如果没有关于senderUser内容的任何信息,例如,您可能只是拼错了字段的名称,我们所能做的就是在生成错误的if之前添加以下内容,以更优雅地响应错误:

if (senderUser.get("friendIds") === undefined) {
    response.error("The sender does not have any friends, cannot send push.");
}

main.js?索引?msgToSend的内容?查看博客链接以了解这些术语。这里没有定义main.js,因此无法确定indexOf的使用。并且您的代码使用msgToSend,您没有提供它的内容。如果您理解这个问题,您可以提供任何解决方法。