2

I am stuck. I am retrieving data from parse.com and trying to dynamically add them to their respective fields. What am I messing up on? I can console.log the data, so my get request is working. Thank you.

var parseData = function() {

    var orderform = Parse.Object.extend("OrderForm");
    var query = new Parse.Query(orderform);
    query.find({
        success: function (results) {

            var tableRow = $('<tr />', {class: 'tableRows'});
          var restaurantListP = [];
            var tdId = [];
            var tdEmail = [];
            var tdMenuItems = [];
            var tdNotes = [];
            var tdPhoneNumber = [];
            var table = $('#orderTable > tbody');

            function newRow($table, cols){
                $row = $('<tr/>');
                for (var i = 0; i < cols.length; i++) {
                    $col = $('<td/>');
                    $col.append(cols[i]);
                    $row.append($col[i]);
                }
                table.append($row);
            }

            results.forEach(function (r, i) {
               // tdId = $('<td />', { "id": r.id });
                tdEmail = $('<td />', {email_address: r.attributes.email_address });
                tdMenuItems = $('<td />', {menu_items: r.attributes.menu_items });
                tdNotes = $('<td />', {notes: r.attributes.notes});
                tdPhoneNumber = $('<td />', {phone_number: r.attributes.phone_number});

                newRow(table,[tdId,tdEmail,tdMenuItems,tdNotes,tdPhoneNumber]);
               // $('#orderTable > tbody').append(tableRow).append(restaurantListP[0]);

                console.log(tdMenuItems);
                console.log(tdEmail);
            });

http://jsfiddle.net/DaveDH2/tb6d7w81/

2
  • in jsfiddle you can include ressources on the left "external ressources" copy paste the link an click on the "+" icon Commented Aug 31, 2014 at 6:46
  • 1
    In your table tbody has id=orderTable, & you are trying to get var table = $('#orderTable > tbody'); which won't give anything, say this var table = $('#orderTable'); & let me know. Commented Aug 31, 2014 at 6:56

1 Answer 1

2

There are two major errors:

  1. id="orderTable" is set for <tbody>, not to <table>, so $('#orderTable > tbody') finds nothing. You should either move id="orderTable" to <table>, or rewrite selector to var table = $('#orderTable').
  2. newRow function works incorrectly: it wraps already created <td> with another <td>, making <tr> html code incorrect. This function should be rewritten in something like this:

    function newRow($table, cols)
    {
        var $row = $('<tr/>');
        for (var i = 0; i < cols.length; i++)
        {
            $row.append(cols[i]);
        }
        $table.append($row);
    }
    

Updated fiddle.

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.