gpt4 book ai didi

javascript - 无法传递查询结果以查看并呈现为 JSON

转载 作者:行者123 更新时间:2023-12-03 10:10:28 25 4
gpt4 key购买 nike

我正在尝试查询解析表,并且能够获取数据。然后,我将该数据传递到解析 View 以呈现到 Handlebars 模板中。当我手动将 JSON 数据输入到集合变量中时, View 本身正在工作。

我的问题是数据没有从查询传递到 View 或没有转换为 JSON。我不断收到以下错误:

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);
}
});

我做错了什么?

最佳答案

难道你正在编码,但没有解码?另外,我会检查 this.collection 的类型,特别是 this。自 Backbone.toJSON()适用于模型。

ex. to encode using JSON.stringify() for converting objects to json string to store in db and to decode when after retrieving from db using JSON.parse()

Backbone uses .toJSON()this post explains进一步了解主干中的序列化/反序列化

关于javascript - 无法传递查询结果以查看并呈现为 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30137590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com