Search code examples
javascriptjqueryparse-platformparse-server

Parse Server Query objectId


I'm using the below query in my web app using the Parse Server Javascript SDK. The console log is providing me with a display of the pulled information as expected, except for objectId that displays "undefined".

var query = new Parse.Query("myClass");
query.include("product");
query.find({

    success: function (results) {

        $scope.items = [];

        for (i = 0; i < results.length; i++) {

            var p = results[i].get("product");

            var item = {
                id: results[i].get("objectId"),
                barcode: p.get("barcode"),
                productName: p.get("name"),
                imageUrl: p.get("image"),
                desiredStock: results[i].get("desiredStock"),
            }

            $scope.items[$scope.items.length] = item;
            console.log(item);

        }

        $scope.$apply();
    },
    error: function (error) {
        console.log("Query Error: " + error.message);
    }
})

How do I go about obtaining the objectId into item.id?


Solution

  • You can write:

    results[i].id
    

    That's the best way to get the objectId with the Parse JS SDK