How to add extra attribute to Parse Signup functio

2019-05-31 10:40发布

I want to add an extra attribute to my parse SignUp function. My code is like

signUp: function(e) {
  var self = this;
  var username = this.$("#signup-username").val();
  var password = this.$("#signup-password").val();
  var sex=this.$("#signup-sex").val();
  Parse.User.signUp(username, password, sex, { ACL: new Parse.ACL() }, {
    success: function(user) {
      new ManageTodosView();
      self.undelegateEvents();
      delete self;
    }

If I pass only username and password, it works and adds a user to database.

3条回答
Explosion°爆炸
2楼-- · 2019-05-31 10:58
var attrs = {ACL: new Parse.ACL(), email: "email@email.com"};

Parse.User.signUp(username, password, attrs, {

    success: function(user) {
      //Set the code for sucess
    },

    error: function(user, error) {
     alert("Error: " + error.code + " " + error.message);
    }
});
查看更多
乱世女痞
3楼-- · 2019-05-31 11:13

The documentation shows only 4 arguments for the Parse.User.signUp function: http://www.parse.com/docs/js/symbols/Parse.User.html#signUp

My guess is this will do the trick:

signUp: function (e) {
    var self = this;
    var username = this.$("#signup-username").val();
    var password = this.$("#signup-password").val();
    var sex = this.$("#signup-sex").val();
    var otherAttribute = 'test';
    Parse.User.signUp(username, password, {
        sex: sex,
        newAttribute: otherAttribute,
        ACL: new Parse.ACL()
    }, {
        success: function (user) {
            new ManageTodosView();
            self.undelegateEvents();
            delete self;
        }
    }
}
查看更多
姐就是有狂的资本
4楼-- · 2019-05-31 11:14

You can do it like this

var user = new Parse.User();
user.set('username',name);
user.set('YOUR_COLUMN','ITS_VALUE');
user.set('password',password);
user.set('YOUR_COULMN','ITS_VALUE');

user.signUp(null,{
    success:function(user){
        NEXT OPERATION
    },
    error:function(error){
        res.send('error::'+error.message);
  }

});
查看更多
登录 后发表回答