我第一次使用 parse.com 并寻找使用 javascript api 获取 json 响应的方法。实际上,我使用车把作为模板引擎并尝试获取 json 响应表单 parse.com,以便我可以轻松地将其传递给车把模板。目前,我正在获得需要像 result.get("title") 这样的对象响应。我搜索了 parse.com javascript 指南和文档,但找不到执行此操作的方法。我想从 parse.com 类中获取所有提要记录作为 json。有什么办法可以解决这个问题吗?
这是车把模板脚本::
<script id="post-template" type="text/x-handlebars-template">
{{#each feeds}}
<div class="post" style="padding-top: 5px; width: 307px; margin: 0 auto;" >
<div style="background: rgba(255,255,255, 0.5); text-align: left;">
<img src="{{post-img}}" alt="image"/>
<p>{{post-mes}}</p>
<p style="position: relative;">
<img src="{{post-by-img}}" alt="image" /><label> By @{{post-by}}</label>
<label class="ago" style="vertical-align: top; position: absolute; right: 10px; top: 18px; height: 20px;">{{post-dt}}</label>
</p>
</div>
<div>
<a href="javascript: alert('Like')" class="button like" >Like</a>
<a href="javascript: alert('Comment')" class="button comment" >Comment</a>
<a href="javascript: alert('Share')" class="button share" >Share</a>
</div>
</div>
{{/each}}
</script>
我用来测试模板的示例 json::
feeds:[
{
'post-img': 'assets/images/photo1.png',
'post-mes': 'Before the party, with @Marie',
'post-by': 'Naza',
'post-by-img':'assets/images/by.jpg',
'post-dt': '5 min'
},
{
'post-img': 'assets/images/photo1.png',
'post-mes': 'Before the party, with @Marie',
'post-by': 'Naza',
'post-by-img':'assets/images/by.jpg',
'post-dt': '10 min'
},
{
'post-img': 'assets/images/photo1.png',
'post-mes': 'Before the party, with @Marie',
'post-by': 'Naza',
'post-by-img':'assets/images/by.jpg',
'post-dt': '15 min'
}
]
和 parse.com 脚本::
var feedsObject = Parse.Object.extend("feeds");
var query = new Parse.Query(feedsObject);
query.find({ ... });
我喜欢得到它如下::
query.find({
success: function(feeds){
//load home page template
var source = $('#post-template').html();
var template = Handlebars.compile(source);
var html = template(feeds); // here's example with some details [link](http://screencast.com/t/XvPFuafRuIW)
$('#home .content').append(html);
},
error: function(object, error){
console.log(error);
}
});
提前致谢!!!