[英]Parse.com - Cannot add additional fields to User
剛開始使用Parse.com並遵循他們的JavaScript ToDo應用程序教程並遇到一些問題。
基本上,它可以完美運行並在我只有用戶名和密碼時發布到Parse數據庫中,但是如果我嘗試添加任何其他字段(如電子郵件或電話),它將不會將其發送到數據庫中。 我已經在我的Parse數據庫中定義了電子郵件和電話字段。
任何幫助,將不勝感激。 謝謝!
我的HTML為我的形式:
<script type="text/template" id="login-template">
<header id="header"></header>
<form class="signup-form">
<h2>Sign Up</h2>
<div class="error" style="display:none"></div>
<input type="text" id="signup-username" placeholder="Username" />
<input type="password" id="signup-password" placeholder="Create a Password" />
<input type="email" id="signup-email" placeholder="Email" />
<input type="text" id="signup-phone" placeholder="Phone" />
<button>Sign Up</button>
</form>
</div>
</script>
我的JS:
var LogInView = Parse.View.extend({
events: {
"submit form.signup-form": "signUp"
},
el: ".content",
initialize: function() {
_.bindAll(this, "signUp");
this.render();
},
signUp: function(e) {
var self = this;
var username = this.$("#signup-username").val();
var password = this.$("#signup-password").val();
var email = this.$("#signup-email").val();
var phone = this.$("#signup-phone").val();
Parse.User.signUp(username, password, email, phone, { ACL: new Parse.ACL() }, {
success: function(user) {
new ManageTodosView();
self.undelegateEvents();
delete self;
},
error: function(user, error) {
self.$(".signup-form .error").html(error.message).show();
self.$(".signup-form button").removeAttr("disabled");
}
});
this.$(".signup-form button").attr("disabled", "disabled");
return false;
},
render: function() {
this.$el.html(_.template($("#login-template").html()));
this.delegateEvents();
}
});
您應該使用以下語法,例如javascript docs( https://parse.com/docs/js_guide )中指定的語法:
var user = new Parse.User();
user.set("username",username);
user.set("password",password);
user.set("email",email);
user.set("phone",phone);
user.signUp(null,{
success:function(user){...},
error:function(user,error){...}
});
您可以使用set方法添加所需的任何字段。
我必須將<!--<button>Submit</button>--> to <!--<input type="submit"></input>-->
才能使它正常工作,但后來做到了。 謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.