Display json response from parse.com using handlebars

断了今生、忘了曾经 提交于 2019-12-23 12:04:08

问题


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


回答1:


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

 var html = template(results[0]);



回答2:


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

var html = template(results[0].attributes);



回答3:


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



来源:https://stackoverflow.com/questions/14784907/display-json-response-from-parse-com-using-handlebars

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!