【问题标题】:New object not appearing in Parse data browser解析数据浏览器中未出现新对象
【发布时间】:2014-04-23 20:29:19
【问题描述】:

我希望在用户在我的 iOS 应用中注册时创建一个新的 userCategory 对象。我认为最好的方法是在注册成功后调用 Parse 云代码函数来触发对象的创建。但是,当我检查 Parse 的数据浏览器时,会创建新用户,但不会创建与该用户关联的新 userCategory

objective-c 代码:

// Sent to the delegate when a PFUser is signed up.
- (void)signUpViewController:(PFSignUpViewController *)signUpController didSignUpUser:(PFUser *)user {
    [self dismissViewControllerAnimated:YES completion:NULL];

    [PFCloud callFunctionInBackground:@"userCategoryCreate"
                       withParameters:@{}
                                block:^(NSNumber *ratings, NSError *error) {
                                    if (!error) {
                                        //userCategory created
                                    }
                                }];
}

云代码:

Parse.Cloud.define("userCategoryCreate", function(request, response) {


  // Simple syntax to create a new subclass of Parse.Object.
var UserCategory = Parse.Object.extend("UserCategory");

// Create a new instance of that class.
var userCategory = new UserCategory();


  response.success("userCategory succesfully created!");
});

【问题讨论】:

    标签: javascript ios objective-c parse-platform


    【解决方案1】:

    你应该做类似的事情:

    // Simple syntax to create a new subclass of Parse.Object.
    var UserCategory = Parse.Object.extend("UserCategory");
    
    // Create a new instance of that class.
    var userCategory = new UserCategory();
    
    // set necessary fields for the new entry row ( if needed )
    userCategory.set("categoryName","categoryFoo1");
    ...
    ..
    .
    
    // Then save the object
    
    userCategory.save().then(function(savedObj){
    
     response.success("userCategory succesfully created!");
    
    },function(saveError){
    
     response.error("Unable to create this object");
    
    });
    

    希望对你有帮助

    【讨论】:

    • 我知道你在这里做什么,但是当我使用此代码时,我收到一条错误消息,指出 Error: success/error was not called。知道为什么吗?
    • 对不起,我已经编辑( save() ,Parse.object 的方法返回一个 Promise,所以我忘了调用 promise 方法“then”。如果你不想处理成功或错误,您可以改用“save().always(function(){})” ;)
    猜你喜欢
    • 1970-01-01
    • 2019-06-03
    • 1970-01-01
    • 2015-03-05
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多