Display json response from parse.com using handleb

2019-06-26 05:37发布

I would like to pass a json response to handlebars. I have looked at the parse documentation and stackoverflow questions but I cannot seem to figure this out.

This is the response:

{"results":[{"address":"755 W. Yale","createdAt":"2013-02-09T01:12:15.732Z","updatedAt":"2013-02-09T01:12:15.732Z","objectId":"JomKPfme5M"}]}

This is my handlebars template:

<script id="post-template" type="text/x-handlebars-template">
<h1>{{address}}</h1>
</script>

This is the script

Parse.initialize("xxxxxx", "yyyyyy");

var listingsView = Parse.Object.extend("listings");
var query = new Parse.Query(listingsView);
query.equalTo("objectId", "JomKPfme5M");
query.first({
  success: function(results){

        var source = $('#post-template').html();
        var template = Handlebars.compile(source);
        var html = template(results);
    },
    error: function(object, error){
        console.log(error);
    }
});

Thank you

3条回答
男人必须洒脱
2楼-- · 2019-06-26 06:09

And if Hector's answer doesn't work, try this:

var html = template(results[0].attributes);
查看更多
在下西门庆
3楼-- · 2019-06-26 06:18

If you are using EmberJS Ember-Model-Parse-Adapter is good

查看更多
Animai°情兽
4楼-- · 2019-06-26 06:27

Results is an array. Try passing the first element to the template.

 var html = template(results[0]);
查看更多
登录 后发表回答