2014-10-25 4 views
0

파싱 및 자바 스크립트 SDK 사용.`잡히지 않은 타입 오류 : undefined is not function` 데이터를 저장하려고했습니다.

페이지의 편집 된 데이터를 구문 분석에 다시 저장해야하는이 함수의 문제점을 볼 수 없습니다. 나는

profileSave.set("username", saveusername); 
profileSave.set("email", saveemail.toString); 
profileSave.set("gender", savegender.toString); 

을 할 노력하고있어하지만 왜 이해하지 못하는 곳에 Uncaught TypeError: undefined is not a function 받고 있어요?

// 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

@code 고유 당신은이 질문에 대해 예제를주고 싶어 나는 그것을 받아 들일 수 있습니까? @ @CodeUniquely이 ** 확인 ** 그 이유는 당신의인가 – Dano007

+0

? https://www.parse.com/docs/js_guide#objects-classes – Daedalus

+0

'.toString()'을 호출 할 필요가 없습니다. '.val()'은 항상 문자열을 반환합니다. – Barmar

답변

1

당신은 세트를 호출하기에 객체를 생성해야합니다. 그래서 당신은.

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

를 관심있는 객체를 확장하는 변수를 정의하고 해당 확장 된 형태

var profileSave = new User(); 

의 새로운 객체를 만들 수 있고, 당신은 당신의 세트 (들)을 호출 할 수 있습니다 수 (들)

profileSave.set("username", saveusername); 
profileSave.set("email", saveemail); 
profileSave.set("gender", savegender); 
+0

다시 저장하면 비밀번호를 포함해야합니까? 이게 선택적인 것 같지 않니? – Dano007

+0

미안하지만 잘 모르겠다. 귀하의 코드는 암호를 언급하지 않는 것, 어떤 개체에 어떤 속성이 있는지 또는 응용 프로그램에서 실제로 기대하는 것이 무엇인지 알지 못합니다. 귀하의 응용 프로그램이 당신이 하나를 보낼 필요가 있다면 당신은 다음 중 하나를 보낼 필요가 없다면, 당신이 선택할 수 있습니다, 당신까지 정말 ... –

관련 문제