JavaScript/jQuery代码块未正确更新parse.com类对象 [英] JavaScript/jQuery code block is not updating parse.com class object correctly

查看:73
本文介绍了JavaScript/jQuery代码块未正确更新parse.com类对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望下面的parse.com/javascript代码块将所选的"badeselected"变量保存到parse类"myBadges"中,并自动创建与"_USer"类的关系.

I would have expected the following parse.com/javascript code block to save the selected "badeselected" variable to the parse class "myBadges" and automatically create a relationship back to the "_USer" class.

控制台日志中没有返回任何错误,但是"myBadges"类中也没有添加任何记录.

There are no errors being returned in the console log, however neither are there any records being added to the "myBadges" class.

我不确定我在这里犯了什么错误?

I'm not sure what error I've made here?

    Parse.initialize("XXXXX", "XXXXX");

var badgeselected = $("#go").attr("src") 
var contact = Parse.Object.extend("myBadges");
var contact = Parse.User.current();

$(document).ready(function () {
            $("#send").click(function () {
               contact.set("BadgeName", badgeselected);
                     console.log("done");

                contact.save(null, {
                    success: function (results) {
                        // The object was saved successfully.
                        location.reload();
                    },
                    error: function (contact, error) {
                        // The save failed.
                        // error is a Parse.Error with an error code and description.
                        alert("Error: " + error.code + " " + error.message);
                    }
                });
            });
        });

推荐答案

您两次声明联系.首先是一个名为myBadges的扩展,然后是当前用户(放弃第一个).在数据浏览器中检查当前用户对象.您应该在那里找到徽章.

You are declaring contact twice. First as an extension called myBadges, and then as current user (discarding the first). Check the current user object in the data browser. You should find the badges there.

更新

以下是javascript指南中的示例:

Here is an example from the javascript guide:

var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();

gameScore.set("score", 1337);
gameScore.set("playerName", "Sean Plott");
gameScore.set("cheatMode", false);

gameScore.save(null, {
  success: function(gameScore) {
    // Execute any logic that should take place after the object is saved.
    alert('New object created with objectId: ' + gameScore.id);
  },
  error: function(gameScore, error) {
    // Execute any logic that should take place if the save fails.
    // error is a Parse.Error with an error code and description.
    alert('Failed to create new object, with error code: ' + error.description);
  }
});

您应该能够在您的jquery代码中使用它.看看他们如何首先将GameScore声明为扩展,然后再将gameScore声明为新的GameScore();. 然后他们在对象上设置值.

You should be able to use this in your jquery code. See how they first declare GameScore as an extension, and then gameScore as new GameScore(); And THEN they set the values on the object.

更多信息: https://parse.com/docs/js_guide

这篇关于JavaScript/jQuery代码块未正确更新parse.com类对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆