Reputation:
I am working with Parse for Javascript, and I have managed to store items in columns in parse called Subject and Message, but my problem is that I would like to display all of them.
Below is the javascript code:
var currentUser = Parse.User.current();
var Message = Parse.Object.extend("Message");
var query = new Parse.Query(Message);
query.equalTo("user", currentUser);
query.find({
success: function(messages) {
}
});
My problem is in relating the javascript code to the html so that it displays all of the message with its subject in a table. Any help would be greatly appreciated.
Upvotes: 1
Views: 808
Reputation: 4114
I'd recommend using Underscore.js's templating functionality. Here's an example of how to use it:
// Using Underscore.js to create a function called 'template'
var template = _.template($('#messages-template').text());
// Passing in an object as an argument to the 'template' function
var compiled = template({ messages: <array of messages from Parse> });
// Appending into the body the HTML that was created from merging the object into the template
$(body).append(compiled);
<script type="text/template" id="messages-template">
<table>
<tbody>
<% messages.forEach(function(message) { %>
<tr>
<td><%= message %></td>
</tr>
<% }); %>
</tbody>
</table>
</script>
Be sure to check out the docs for a better understanding of how to use it to it's fullest capabilities - http://underscorejs.org/#template .
Upvotes: 1