Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I recently posted this question to figure out how to create a table of data in HTML/JS using Parse.com

I am now working with a new template, where I am dealing with an already existing div table and want to populate it dynamically with my Parse.com data.

Here is the HTML code from the website template:

<div class="sidebarbox">
    <div class="sidebarbox-title">
        <h3>Latest Results</h3>
    </div>
    <!-- TABLE -->
    <div class="fixture-row">
        <a href="#">
            <div class="fixture-row-left">Consectetur FC
                <div>?</div>
            </div>
            <div class="fixture-row-right">
                <div>?</div>Voluptate Cillum FC</div>
        </a>
    </div>
</div>

And this is the HTML/javascript code I currently have which successfully creates a HTML table with my Parse.com data inside.

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <script type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript"
        src="http://www.parsecdn.com/js/parse-1.2.18.min.js"></script>
</head>
<body>
    <h3>Current season First Team results</h3>
    <table id="first-team-results-table">
        <col width="150">
        <col width="150">
        <col width="80">
        <col width="150">
        <col width="80">
        <tbody>
            <tr>
                <th>Opposition</th>
                <th>Competition</th>
                <th>Home/Away</th>
                <th>When</th>
                <th>Score</th>
            </tr>
        </tbody>
    </table>
    <h3>Current season Reserve Team results</h3>
    <table id="reserve-team-results-table">
        <col width="150">
        <col width="150">
        <col width="80">
        <col width="150">
        <col width="80">
        <tbody>
            <tr>
                <th>Opposition</th>
                <th>Competition</th>
                <th>Home/Away</th>
                <th>When</th>
                <th>Score</th>
            </tr>
        </tbody>
    </table>
    <script type="text/javascript">
src="//www.parsecdn.com/js/parse-1.2.18.min.js";
Parse.initialize("jtYdOpyKQ6SXFLqaGcpoG20yXyX9KlPHUzgg6jAJ", "TMRegOlA8nCui4sTN8d9hmQG8k8FVeESc2GnRwVH");
var firstTeamResults = Parse.Object.extend("Results");
var query = new Parse.Query(firstTeamResults);
query.equalTo("team", "DVFC Firsts");
query.descending("dateTime");
query.find(
{
    success: function(results)
    {
        for (var i = 0; i < results.length; i++) {
            var object = results[i];
            (function($) {
                $('#first-team-results-table').append('<tr><td>' 
                    + object.get('oppositionName') 
                    + '</td><td>' 
                    + object.get('competition') 
                    + '</td><td>' 
                    + object.get('homeAway') 
                    + '</td><td>' 
                    + object.get('dateTime') 
                    + '</td><td>' 
                    + object.get('score') 
                    + '</td></tr>');
            })(jQuery);
        }
    },
    error: function(error) {
        alert("Error: " + error.code + " " + error.message);
    }
});
var reserveTeamResults = Parse.Object.extend("Results");
var query = new Parse.Query(reserveTeamResults);
query.equalTo("team", "DVFC Reserves");
query.descending("dateTime");
query.find(
{
    success: function(results)
    {
        for (var i = 0; i < results.length; i++) {
            var object = results[i];
            (function($) {
                $('#reserve-team-results-table').append('<tr><td>' 
                    + object.get('oppositionName')  
                    + '</td><td>'  
                    + object.get('competition')  
                    + '</td><td>'  
                    + object.get('homeAway')  
                    + '</td><td>'  
                    + object.get('dateTime')  
                    + '</td><td>'  
                    + object.get('score')  
                    + '</td></tr>');
            })(jQuery);
        }
    },
    error: function(error) {
        alert("Error: " + error.code + " " + error.message);
    }
});
    </script>
</body>
</html>

Any help on how to combine the two, and get the Parse.com data into the div table would be highly appreciated.

share|improve this question

1 Answer 1

I strongly recommend you look into using something like KendoUI (which is now FREE/Open-Source except for the more advanced controls), it makes things like this very very easy.

Also as a side note, you should wrap your entire script block in a single jQuery doc load instead of using the existing construct inside a loop as you have.

jQuery(function($) {
    // all your code here will only run once the page is loaded
    // and can use $ safely

    // ... code ...
});

As for your question, I'm not sure what structure the content is meant to have inside the "div table", but given what you have provided you can find the <div>?</div> tag as follows:

$('.fixture-row-left div:first')

This assumes there are no other elements with class-"fixture-row-left", otherwise you'll need some more reliable way to identify the correct element (id attribute is best).

Once you have the attribute, you can append HTML much like you have been doing.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.