无法保存变量中保存的数据-没有“设置"方法 [英] Unable to save data held in a variable - has no method 'set'

查看:91
本文介绍了无法保存变量中保存的数据-没有“设置"方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已更新.

此代码块将用户的Facebook连接保存到"fbdata"中,并保存在div的"friends-list-container"中.

This code block takes the users facebook connections and saves them into the "fbdata" and within the div "friends-list-container".

这是有错误的页面.

然后我尝试将数据保存到parse.com,并在以下图片中显示以下错误.

I'm then attempting to save the data to parse.com and have the following error shown the image below.

<!doctype html>

     <!-- Runs Parse and FB code that uses Facebook authentication to login 
user to the site and redirects them to the main content area. This page is
fired from the Facebook button being clicked on the site landing page-->


        <html lang="en">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1"> 
            <meta name="description" content="fresh Gray Bootstrap 3.0 Responsive Theme "/>
            <meta name="keywords" content="Template, Theme, web, html5, css3, Bootstrap,Bootstrap 3.0 Responsive Login" />
            <meta name="author" content="Adsays"/>
            <title>Parse JavaScript Todo App</title>
            <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
            <script src="scripts/underscore-1.1.6.js"></script>
            <script src="http://www.parsecdn.com/js/parse-1.2.13.min.js"></script>



        </head>
        <body>

            <!-- Important, must be on the page -->
            <div id="fb-root"></div>    


            <!-- Initialize the Parse object-->
            <script type="text/javascript">     
            Parse.initialize("79tphN5KrDXdjJnAmehgBHgOjgE2dLGTvEPR9pEJ", "9lblofQNZlypAtveU4i4IzEpaOqtBgMcmuU1AE6Y");

            var user = Parse.User.current();
        //Fb app information//

        window.fbAsyncInit = function() {
            Parse.FacebookUtils.init({
                appId      : '523753101076577',
                channelUrl : 'http://www.kudosoo.com/channel.html',
                status     : true,
                cookie     : true,
                xfbml      : true
            });

        //FB user authentication script, after this completes it fires todos_two.js to redirect user to main content page//


        FB.getLoginStatus(function (response) {
          if (response.status === 'connected') {
            FB.api('/me/friends', function(response){
              if (response && response.data){
                var contact = new Parse.User();
                var fbdata=response.data;
                var divTarget=document.getElementById("friends-list-container");
              for (var friendIndex=0; friendIndex<fbdata.length; friendIndex++)
            {      var divContainer = document.createElement("div");
                   divContainer.innerHTML="<b>" + fbdata[friendIndex].name + "</b>";
                   divTarget.appendChild(divContainer);
            }

        var contact = new Parse.User();
        var contact = new Contact();



            $(document).ready(function () {
                         var username = $("#friends-list-container").val();
                         contact.set("facebookFriends", fbdata.toString());
                        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);
                            }
                        });
                    });


              } else {
                console.log('Something goes wrong', response);
              }
            });

          }
        });



        };

        (function(d, s, id){
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {return;}
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));


        </script>
        <div id="friends-list-container"></div>
        </body>
        </html>

这是错误.

推荐答案

尝试替换此行:

var contact = Parse.Object.extend("_User");

从聊天对话中更新,这就是解决问题的方法:

Updated from the chat conversation, this is what solved the problem:

如果要将朋友列表存储在当前用户的数组中,则需要Parse.User.current():

If you want to store the friends list in an array on the current user, then Parse.User.current() is what you want:

var contact = Parse.User.current()

这篇关于无法保存变量中保存的数据-没有“设置"方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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