Akshay Arora
Akshay Arora

Reputation: 1945

Unable to get values of Pointer Fields values Parse + React

I am making a React + Parse app. To model a relation, I have used a pointer field pointing to object of another class in one of my class.

var OfferListings = React.createClass({

    mixins: [ParseReact.Mixin],

    observe: function(){


        var off = (new Parse.Query('OffersLive'));

        return {

            offers: off    
        }

    },


    render: function(){

        var myObj = this;

        return(
            <div>
            <ul className="list-group">
            {

                this.data.offers.map(function(c){
                    console.log(c);

                    return <li key={c.objectId} className="list-group-item">{c.get("PostedBy").PlaceName}</li>

                })
            }
            </ul>
            </div>
            );
    }




});

The Parse documentation states that I can call a get method on the object to get the respective pointer object's fields. (PlaceName is one of the field in the class pointed at).

But when I call get as shown above, I get an error in the console, c.get is not a function.

My question is, how do I get the values of this pointer field?

Is there some another way of doing it in a Parse + React application?

Thanks.

Upvotes: 0

Views: 400

Answers (1)

Josh Geller
Josh Geller

Reputation: 86

Include will populate the pointer with the data from the joined table/class:

var off = (new Parse.Query('OffersLive').include('PostedBy'));

then you can access the fields of the pointed-to table/class using dot-notation:

return <li key={c.objectId} className="list-group-item">{c.PostedBy.PlaceName}</li>

Upvotes: 1

Related Questions