0

我创建了一个视图来呈现由 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"…}

传递给视图似乎是正确的集合,但未正确呈现。此集合正确呈现的广告示例:

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

而不起作用的集合的模型:数组[]是:

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;
    },
4

0 回答 0