ParseReact icon indicating copy to clipboard operation
ParseReact copied to clipboard

Can't get objects from Parse

Open Tim77277 opened this issue 8 years ago • 0 comments

Hi I tried to use the example code on your README and changed the Parse Class Name to get the desired objects, but it crashes in render function "this.data.ads.map". It gives the message "can not call map of undefined". Does it means that Parse.Query did not get trigger? I have tried to use the Parse JS SDK and got the objects with no issue so I think this issue is not something related to configuration.

import React, { Component } from 'react';
import Parse, {Query} from 'parse';
import ParseReact from 'parse-react';

Parse.initialize('MY_APPLICATION_ID');
Parse.serverURL = 'MY_PARSE_SERVER_URL';

var Advertisements = React.createClass({
  mixins: [ParseReact.Mixin], // Enable query subscriptions

  observe: function() {
    // Subscribe to all Advertisement objects, ordered by creation date
    // The results will be available at this.data.ads
    return {
      ads: (new Parse.Query('Advertisement')).ascending('createdAt')
    };
  },

  render: function() {
    // Render the text of each comment as a list item
    return (
      <ul>
        {this.data.ads.map(function(c) {
          return <li>{c.text}</li>;
        })}
      </ul>
    );
  }
});

class App extends React.Component {
    render() {
      return <div >< Advertisements /></div>
    }
}

export default App;

Tim77277 avatar Sep 20 '17 14:09 Tim77277