【问题标题】:How to send array of data to Parse Cloud Code?如何将数据数组发送到 Parse Cloud Code?
【发布时间】:2014-07-18 22:51:43
【问题描述】:

我正在尝试在 Parse 云代码函数参数中发送一组联系人电子邮件(字符串)。我是这样做的:

HashMap<String, ArrayList<String>> params = new HashMap<>();
ArrayList<String> array = new ArrayList<>();
array.add("contact email 1");
array.add("contact email 2");
array.add("contact email 3");

params.put("contacts", array);

ParseCloud.callFunctionInBackground("cloudFunctionName", params, new FunctionCallback<Object>() {
    @Override
    public void done(Object o, ParseException e) {
        // do something
    }
});

我在这里定义我的云功能: contacts 应该类似于:{"contacts" : ["contact email 1", "contact email 2", "contact email 3"]}。我对每封电子邮件进行迭代,并对每封电子邮件执行一些逻辑。

var _ = require("underscore");

Parse.Cloud.define("cloudFunctionName", function (request, response) {
var contacts = request.params.contacts;

_.each(contacts, function(contactEmail) {
    var userQuery = Parse.Query(Parse.User);

    userQuery.equalTo("email", contactEmail);

    userQuery.first().then(
        function(user) {
            // there is a user with that email
        },
        function(error) {
            // no user found with that email
});

});

我遇到的问题是有时contactEmail 未定义。

我收到错误:Result: TypeError: Cannot call method 'equalTo' of undefined 在线 userQuery.equalTo("email", contactEmail);

即使我写了if(typeof contactEmail != "undefined") { userQuery.equalTo("email", contactEmail); },我仍然得到错误。

在添加到数组之前,我还要检查 emailString 是否为空?

我该如何解决这个问题?

【问题讨论】:

    标签: java javascript android arrays parse-platform


    【解决方案1】:

    更新您的 JavaScript 以创建用户查询,如下所示:

    var userQuery = new Parse.Query(Parse.User);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多