0

It seems when I am trying to retrieve information from my parse data I am having no issue displaying the information from the user table onto my document but when I try to query another object & insert it into an id element with jQuery using either text();, html();, or val(); I either get nothing or the text becomes into [object Object]. below is the code I have written down. I also tried a JavaScript method & same output I get [object Object].

    var currentUser = Parse.User.current();



  if (currentUser) {
   var UserInfo = Parse.Object.extend("UserInfo");
   var query = new Parse.Query(UserInfo);
   query.equalTo("user", currentUser);
   query.find({
           success: function(UserInfo) {

          document.getElementById('fieldone').innerHTML = query.get("fieldone");

            $('#fieldtwo').text(query.get("fieldtwo"));

            $('#startDate').val(query.get("startdate"));

            $('#endDate').text(query.get("enddate"));
     },
        error: function(object, error) {
               }

              });

       }
  • 2
    Try `console.log(JSON.stringify(query.get("fieldone")))` and see what you get.. – Dilip Rajkumar Nov 23 '15 at 01:36
  • `[object Object]` is the default result from [converting a plain `Object` to a string](http://stackoverflow.com/questions/4750225/what-does-object-object-mean). If you want more information from the object, you'll have to either use something to format it differently (perhaps `JSON.stringify()`) or access the values held by its properties. – Jonathan Lonowski Nov 23 '15 at 01:38
  • does query.get return an object or a stirng? because by default text and val() accept string for parameters so it automatically calls .toString() which for many objects just returns "[object Object" – Binvention Nov 23 '15 at 01:45
  • Hello everyone thanks on speedy replies I appreciate it! So when I console log I get {"_resolved":false,"_rejected":false,"_resolvedCallbacks":[],"_rejectedCallbacks":[]} – Erick Funes Nov 23 '15 at 01:56

1 Answers1

0

query.get is something similar to query.find and returns a promise and not your data. (Notice what you logged out).

Instead of writing query.get("fieldtwo"), you should be writing UserInfo[i].get("fieldtwo") because the queried data is present in the returned UserInfo object, after the success callback is resolved.

Your code should look like:

var currentUser = Parse.User.current();



  if (currentUser) {
   var UserInfo = Parse.Object.extend("UserInfo");
   var query = new Parse.Query(UserInfo);
   query.equalTo("user", currentUser);
   query.find({
           success: function(UserInfo) {

    for(var i = 0 ; i < UserInfo.length; ++i)
    {
       var mydata = UserInfo[i].get("fieldone");
       // do anything with mydata
     }

     },
        error: function(object, error) {
               }

              });

       }
Akshay Arora
  • 1,953
  • 1
  • 14
  • 30