我正在尝试Parse.Collection
从parse.com中的类获取a 。一切正常,但是获取会返回一个空数组(并且parse.com中的类不为空)。我不知道该怎么用Parse.Query
。
我究竟做错了什么?如何进一步调试以缩小错误?
谢谢
这是我的代码:
Parse.initialize("XXX", "XXX");
var AppRouter = Parse.Router.extend({
routes: {
"class-list": "listClasses",
},
initialize: function () {
var self = this;
this.loginView = new LoginView();
// ----------------------------------------------------CLASS
// |-----> Collection
var ClassModel = Parse.Object.extend({
className: "Classes"
});
this.classModel = new ClassModel();
// |-----> Query
var ClassQuery = new Parse.Query(ClassModel);
ClassQuery.find({
success: function(results) {
// results is an array of Parse.Object.
return results;
},
error: function(error) {
// error is an instance of Parse.Error.
}
});
// |-----> Collection
var ClassCollection = Parse.Collection.extend({
model: ClassModel,
query: ClassQuery
});
this.classCollection = new ClassCollection();
this.classCollection.fetch();
// |-----> View
var ListClassView = Parse.View.extend({
initialize: function () {
//this.listenTo(this.collection, "reset", this.render);
},
render: function () {
this.$el.html(Handlebars.templates.class_list(this.collection));
return this;
}
});
this.listClassView = new ListClassView({
collection: self.classCollection
});
},
});
var app = new AppRouter();
Parse.history.start();
这是有关野生动物园要求的信息:
在success:
处理程序中,您有以下几行:
return results;
我不确定您在这里期望什么,但是将会发生的事情是您将结果返回给调用成功处理程序的Parse代码。实际上,整个find()
呼叫应该被删除。要在通话fetch()
的收集将调用底层查询你。
从我在Collections的文档中可以看到的,如果您希望Collection基于查询,则可以按以下步骤进行操作:
// UpperCamel for object we can use with new
var ClassModel = Parse.Object.extend("Classes");
// lowerCamel for a local variable
var classQuery = new Parse.Query(ClassModel);
// you don't call find() directly on the query, that'll mess things up
// UpperCamel for a collection definition
var ClassCollection = Parse.Collection.extend({
model: ClassModel,
query: classQuery
});
this.classCollection = new ClassCollection();
// at this point I would suggest connecting to the view first, then call fetch()
// ... ListClassView declaration skipped for brevity ...
this.listClassView = new ListClassView({
collection: self.classCollection
});
this.classCollection.fetch();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句