我们从一个数组创建了一个模型集合,如下所示。我们的问题是:集合是否会保留与原始数组中相同的元素/模型顺序?换句话说,Collection 中是否保证(源数组的)相同顺序?
var colorsData = [
{
name: 'red'
},
{
name: 'blue'
},
{
name: 'green'
},
.....
.....
.....
//other colors
];
var Color = Backbone.Model.extend({
defaults: {
name: 'white'
}
});
var ColorCollection = Backbone.Collection.extend({
model: Color
});
var colorCollection1 = new ColorCollection(colorsData); //creating a collection from the source array colorsData.