samedi 9 mai 2015

Unable to pass result of a query to view and render into JSON

I am trying to query a Parse table and I am able to get the data out. I am then passing that data to a Parse View to be rendered into a handlebar template. The view in itself is working when I manually input JSON data into the collection variable.

My problem is that the data is not getting passed to the View from the query or not getting converted to JSON. I keep getting the following error:

Uncaught TypeError: this.collection.toJSON is not a function

// render template with context data 
var StoresView =  Parse.View.extend({
template: Handlebars.compile($('#storetable-tpl').html()),
render: function(){ 
    var collection = { storeList: this.collection.toJSON() };
    this.$el.html(this.template(collection));
}
});

// query the store table data
allStores.equalTo("shape","Round");
allStores.limit(10);
allStores.descending("updatedAt");
allStores.find({
success: function(results) {
    var storesView = new StoresView({ collection: results });
    storesView.render();
    $('#stores-table').html(storesView.el);
} 
});  

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire