使用Parse和JavaScript SDK。
我无法看到这个函数有什么问题,应该将页面上编辑的数据保存回解析。我正在尝试Uncaught TypeError: undefined is not a function
profileSave.set("username", saveusername);
profileSave.set("email", saveemail.toString);
profileSave.set("gender", savegender.toString);
但不明白为什么?
// Saves the users profile information
$('#save').click(function (e) {
ProfileSave();
});
///
function ProfileSave() {
var profileSave = Parse.Object.extend("_User");
var saveusername = $('#username').val();
var saveemail = $('#email').val();
var savegender = $('#gender').val();
profileSave.set("username", saveusername.toString);
profileSave.set("email", saveemail.toString);
profileSave.set("gender", savegender.toString);
profileSave.save(null, {
success: function(profileSave) {
//success
},
error: function(profileSave, error) {
// Fail
}
});
}
完整代码
<div class="container">
<!--Data is stored in these divs but not they are not displayed to the user!-->
<div id="div_uname" style="display:none;"></div>
<div id="div_email" style="display:none;"></div>
<div id="div_gender" style="display:none;"></div>
<div id="profile_pic"></div>
</div>
<!--This is what the user sees. The id calls JS that enables the input field to be edited!-->
<!--Displays user profile information on the page!-->
<div class="container">
<h4>General Features</h4>
<ul>
<li>
<input type="text" class="div_uname" id="username" value="" />
</li>
<li>
<input type="text" class="div_email" id="email" value="" />
</li>
<li>
<input type="text" class="div_gender" id="gender" value="" />
</li>
<li>
<button class="button button-blue" id="save">Save Name</button>
</li>
</ul>
</div>
<!--This script displays the user profile data on the page and allows the user to update the details -->
<script type="text/javascript">
Parse.initialize("xx", "xx");
Parse.User.logIn("dave", "delvedia", {
success: function(user) {
console.log("Logged in!");
}
});
// Makes sure the current user is selected//
// Pulls the user data from parse and stores in variables//
var user = Parse.User.current();
user.fetch().then(function(fetchedUser) {
var username = fetchedUser.getUsername();
var email = fetchedUser.getEmail();
var gender = user.get("gender");
var imgPaht = user.get("pic");
// Outputs the data to the users view//
// Adds the contents of the variables into the html divs//
document.getElementById("div_uname").innerHTML = username;
$(".div_uname")
.val($("#div_uname").text())
document.getElementById("div_email").innerHTML = email;
$(".div_email")
.val($("#div_email").text())
document.getElementById("div_gender").innerHTML = gender;
$(".div_gender")
.val($("#div_gender").text())
$('<img src="' + imgPaht + '">').load(function() {
$(this).width(400).height(400).appendTo('#profile_pic');
})
}, function(error) {
});
// Saves the users profile information
$('#save').click(function (e) {
ProfileSave();
});
///
function ProfileSave() {
var profileSave = Parse.Object.extend("_User");
var saveusername = $('#username').val();
var saveemail = $('#email').val();
var savegender = $('#gender').val();
profileSave.set("username", saveusername.toString());
profileSave.set("email", saveemail.toString());
profileSave.set("gender", savegender.toString());
profileSave.save(null, {
success: function(profileSave) {
//success
},
error: function(profileSave, error) {
// Fail
}
});
}
</script>
答案 0 :(得分:1)
您需要创建一个可以调用该集的对象。因此,您可以定义一个扩展您感兴趣的对象的变量。
var User = Parse.Object.extend("_User");
然后您可以创建该扩展类型的新对象
var profileSave = new User();
你可以打电话给你的设备并获得(s)
profileSave.set("username", saveusername);
profileSave.set("email", saveemail);
profileSave.set("gender", savegender);