0

我可以获取找到它的模型的集合吗?我想获取模型的集合,用于计算相对于当前模型的前后模型。可以在Backbone中完成吗?

var PhotoView = Backbone.View.extend({
    className: "media-item",
    template: _.template(photoItemTemplate),
    render: function(){
        var data, next;
        data = this.model.toJSON();

        this.$el.html(this.template(data));

        return this;
    },
    prev: function () {
        //this.model.collection = ??
    },
    next: function () {
       //this.model.collection = ??
    }
});
4

2 回答 2

2
var collection = this.model.collection;
var prevModel = collection.at(collection.indexOf(this.model) - 1);
var nextModel = collection.at(collection.indexOf(this.model) + 1);
于 2013-03-06T12:02:59.320 回答
0

this.model.collection也会给你模型所属的集合。

于 2013-03-06T11:56:32.700 回答