简体   繁体   中英

Taking data from a javascript object queried from parse.com

I have a parse.com database which i am querying using the objectID. It returns the data but I can only see it inside the promise object as an attribute, i can't figure out how this works from the documentation, how should i actually get the data and turn it into an object rather than a Promise. Should i call the function after or save it as a variable or something in the success function, do i need to define review somewhere earlier? any example would be awesome

        var query = new Parse.Query("business_and_reviews");
        var results = new Parse.Object("business_and_reviews");
        query.get("pLaARFh2gD", {
            success: function(results) {
                // results is an array of Parse.Object.
            },
            error: function(object, error) {
                // The object was not retrieved successfully.
                // error is a Parse.Error with an error code and message.
            }
        });
        var name = results.get("city");
        console.log(name);

This is the Promise in chrome

镀铬控制台

get() returns only one object with the id.

var query = new Parse.Query("business_and_reviews");
query.get("pLaARFh2gD", {
    success: function(result) {
        var name = result.get("city");
        console.log(name);
    }
});

Here is another example from the document .

var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
query.get("xWMyZ4YEGZ", {
    success: function(gameScore) {
        var score = gameScore.get("score");
        var playerName = gameScore.get("playerName");
        var cheatMode = gameScore.get("cheatMode");
    },
    error: function(object, error) {
        // The object was not retrieved successfully.
        // error is a Parse.Error with an error code and message.
    }
});

Thanks, I solved it now, first had to be inside the success: function, then had to select the info in the object as follows:

        var query = new Parse.Query("business_and_reviews");
        var results = new Parse.Object("business_and_reviews");

        query.get("pLaARFh2gD", {
            success: function(results) {

                console.log(results["attributes"]["city"]);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM