Android: 如何输入值到Parse云代码,例如beforesave

Android: How to input values to Parse cloud code, eg beforesave

在应用程序内部,用户会将带有句点名称的插槽结果上传到 Parse 数据库。但是在上传之前,最好在beforesave之前检查一下period ref是否已经存在,如果DB中已经存在相同的period ref,slot结果将不会被上传。

Cloud.beforesave

Parse.Cloud.beforeSave("check_duplicate", function(request, response) 
{
    var DB = Parse.Object.extend("Record_db"); 
    var query = new Parse.Query(DB);
        query.equalTo("period_ref", request.object.get("period_ref"));
        query.first
        ({
      success: function(object) 
    {
            if (object) 
        {
                response.error("A Period with this ref already exists.");
            } 
        else 
        {
                response.success();
            }
      },
      error: function(error) 
    {
        response.error("Could not validate uniqueness for this period ref object.");
        }
    });  
});

Android代码:

ParseCloud.callFunctionInBackground("check_duplicate", new HashMap<String, Object>(), new FunctionCallback<String>() {
      public void done(String result, ParseException e) 
      {
        if (e == null) 
        {
            Utilities.custom_toast(CurrentResult.this, "cloud success" + result, "gone!", "short");
        }
        else
        {
            Utilities.custom_toast(CurrentResult.this, "cloud error" + e, "gone!", "short");
        }
      }
    });

问题:

这种常见情况没有明确的例子。我想问一下 例如,现在用户想要上传 slot ref 001/2015 结果。所有信息都已在设备上可用,我如何将此期间参考 001/2015 传递给云代码以检查它是否已存在于上传并保存到云数据库的云数据库中?

非常感谢!

你的第一行 Android...

ParseCloud.callFunctionInBackground("check_duplicate", new HashMap(), new FunctionCallback() {

变成

ParseCloud.callFunctionInBackground("check_duplicate", 
new HashMap<String, String>{"period_ref":"001/2015"};, 
new FunctionCallback<String>() {