0

I've been working on an restaurant app that should get the menu from an online database.

This is how I currently and "Manually" populate the menu:

Controller.html

$scope.menu = [{
                     name: 'Espresso',
                     price: 27,
                     qty: 1,
                     desc: "One shot of espresso prepared with 7 grams of ground coffee in a single portafilter. The shot should be 1 ounce of liquid. You have two choices with espresso: ristretto, a very short or “restrained” shot, brewed at less than 2/3 of a demitasse, or luongo, a long pull of espresso brewed so the liquid should be more than 2/3 of a demitasse.",
                     img: "img/espresso.png",
                     active: false,
                     sizes: [{name: "Small", price: 0, active:false},
                             {name: "Medium", price: 5, active:false},
                             {name: "Large", price: 10, active:false}],
                     flavors: [{name: 'Vanilla', price: 8, active: false},
                               {name: 'Almond', price: 8, active: false},
                               {name: 'Hazelnut', price: 8, active: false},
                               {name: 'Caramel', price: 8, active: false}]
                     }]; 

However I can't seem to achieve populating this using Parse, how would I approach this using a query as the following (Which is a working query).

Index.html

<script type="text/javascript">

  Parse.initialize("vGoJDvwwfZBiUFcwfkee7M5vCqL7lLxCgKIFJXDc", "6VRlos6qppaek1uDPPLqpHtmB3fHefOJMqYJNxj9");

  var DrinkMenu = Parse.Object.extend("DrinkMenu");
  var query = new Parse.Query(DrinkMenu);
  query.find({
    success: function(results) {
      alert("Successfully retrieved " + results.length + " items.");
      // Do something with the returned Parse.Object values
      for (var i = 0; i < results.length; i++) {
        var object = results[i];
        alert(object.id + ' - ' + object.get('name'));
      }
    },
    error: function(error) {
      alert("Error: " + error.code + " " + error.message);
    }
  });

</script>

You can notice I can get the variables needed for each item, in this case the name of the first result, which I display in an alert.

Any help is appreciated!

1 Answer 1

1

After Parse.initialize, create a variable, like this:

var arrMenu = [];

then change the line alert(object.id + ' - ' + object.get('name')); to

arrMenu.push({
                     name: object.get('name'),
                     price: object.get('price'),
                     qty: object.get('qty'),
                     desc: object.get('desc'),
                     img: object.get('img'),
                     active: object.get('active'),
                     sizes: object.get('sizes'),
                     flavors: object.get('flavor')
          });

I am supposing that you are storing the info in the Parse Collection with the structure you mentioned. If it is different, let me know.

And, after the brack the closes the for, you add:

$scope.menu = arrMenu;

I hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.