我创建了一个视图来渲染parse.com提取的集合,但如果我调用传递它的视图,则集合不起作用。
获取并发送到视图的功能:
friends: function () {
var self = this;
var User = Parse.Object.extend("User");
var Amici = Parse.Object.extend("User");
var query = new Parse.Query(User);
query.equalTo("objectId", Parse.User.current().id);
query.find({
success: function (user) {
for (var i = 0; i < user.length; i++) {
user[i].relation("amici").query().find({
success: function (amici) {
console.log(amici);
var friendscollection = new Amicizie(amici);
console.log(friendscollection);
var page = new Homelistuser({
model: friendscollection
});
self.changePage(page);
}
});
}
}
});
},
朋友集合的控制台日志是:
child {length: 3, models: Array[3], _byId: Object, _byCid: Object, url: "https://api.parse.com/1/classes/User"…}
它似乎是传递给视图的正确集合,但是没有正确呈现.Ad示例此集合正确呈现:
child {length: 5, models: Array[5], _byId: Object, _byCid: Object, model: function…}
为什么第一个集合在上一个集合中不起作用?
models:有效集合的Array []是:
Models: Array[5]
0: child
1: child
2: child
3: child
虽然模型:不起作用的集合的Array []是:
models: Array[3]
0: Backbone.Model
1: Backbone.Model
2: Backbone.Model
观点:
var Homelistuser = Backbone.View.extend({
tagName: "ul",
id: "list",
template: Handlebars.compile(template),
initialize: function () {
this.model.bind("reset", this.render, this);
$(window).on('orientationchange', this.onOrientationChange);
$(".out").on('click', this.log_out);
$(".prove").on('click', this.prove);
},
events: {
"click .out": "log_out"
},
render: function (eventName) {
$(this.el).empty();
_.each(this.model.models, function (ad) {
$(this.el).append(new SingleUserView({
model: ad
}).render().el);
}, this);
return this;
},
第一个视图调用的视图:
var SingleUserView = Backbone.View.extend({
tagName: "li",
events: {
"click": "goToDetails",
"click .out": "log_out"
},
template: Handlebars.compile(template),
initialize: function () {
this.model.bind("change", this.render, this);
this.model.bind("destroy", this.close, this);
},
render: function (eventName) {
var ad = this.model.toJSON();
console.log(ad);
ad.cid = this.model.cid;
$(this.el).html(this.template(ad));
return this;
},