在Parse中检索列 [英] Retrieve column in Parse
问题描述
$ 我正在使用Parse for Javascript,并且我已经设法将项目存储在解析中的列中,称为Subject和Message,但是我的问题是我想要显示所有项目。 b $ b
以下是JavaScript代码:
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){
$ b}
});
我的问题是将JavaScript代码与html关联起来,以便它显示所有消息主题在表中。任何帮助将不胜感激。
我推荐使用 Underscore.js 的模板功能。这里有一个如何使用它的例子:
JS
/ /使用Underscore.js创建一个名为'template'的函数
var template = _.template($('#messages-template')。text());
//将一个对象作为参数传递给'template'函数
var compiled = template({messages:<来自Parse的消息数组>});
//在体内附加将对象合并到模板中创建的HTML
$(body).append(compiled);
HTML
< script type =text / templateid =messages-template>
< table>
< tbody>
<%messages.forEach(函数(消息){%>
< tr>
< td><%= message%>< / td>
< / tr>
<%}); %GT;
< / tbody>
< / table>
< / script>
请务必查看文档以更好地了解如何将其用于最全面的功能 - http://underscorejs.org/#template 。
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.
I'd recommend using Underscore.js's templating functionality. Here's an example of how to use it:
JS
// 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);
HTML
<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 .
这篇关于在Parse中检索列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!