gpt4 book ai didi

javascript - 在 Parse 中检索列

转载 作者:行者123 更新时间:2023-11-28 00:39:08 25 4
gpt4 key购买 nike

我正在使用 Parse for Javascript,并且我已成功将项目存储在名为“主题”和“消息”的解析列中,但我的问题是我想显示所有这些内容。

下面是 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) {

}
});

我的问题是将 javascript 代码与 html 相关联,以便它在表格中显示所有消息及其主题。任何帮助将不胜感激。

最佳答案

我建议使用Underscore.js的模板功能。以下是如何使用它的示例:

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>

请务必查看文档,以便更好地了解如何充分利用它的功能 - http://underscorejs.org/#template .

关于javascript - 在 Parse 中检索列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28136101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com