不渲染复合视图,如何重新排列集合中模型的索引。
我必须对复合视图的itemView进行排序。我使用过Jquery UI可排序插件。它在DOM中运行良好但我想反映Backbone Collection中的重新排列,而不是渲染Composite视图。
答案 0 :(得分:2)
您可以使用comparator
上的Collection
,而您的复合视图将自行处理渲染:
示例强>
var Member = Backbone.Model.extend({
defaults: {
name: '',
credit: 0,
memberSince: 0
}
});
// Specify what field in the model to sort with:
var Members = Backbone.Collection.extend({
model: Member,
comparator: 'credit'
});
// The comparator can also be a function:
var Members = Backbone.Collection.extend({
model: Member,
comparator: function(model) { return model.get('memberSince'); }
});