【发布时间】:2015-05-09 16:23:17
【问题描述】:
我正在尝试查询 Parse 表,并且能够获取数据。然后我将该数据传递给 Parse View 以呈现到车把模板中。当我手动将 JSON 数据输入到集合变量中时,视图本身正在工作。
我的问题是数据没有从查询传递到视图或没有转换为 JSON。我不断收到以下错误:
未捕获的类型错误:this.collection.toJSON 不是函数
// 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);
}
});
我做错了什么?
【问题讨论】:
-
我刚刚注意到,问题不在于将数据从查询传递到视图。因为当我更改 'code'var collection = { storeList: this.collection };然后我得到一个数组中的数据。
标签: javascript json parse-platform handlebars.js