Backbone 文档是这么说的 -
Collections are ordered sets of models.
但是有序集到底是什么?我知道它是一个对象,但我不理解数据结构,因为它有像对象一样的键-
Object.keys(exampleCollection
//returns ["length", "models", "_byId", "currentSort", "fetched", "_listenerId", "_events", "comparator"]
但是你可以像map一样调用数组函数-
exampleCollection.map(function (mod) {console.log(mod)})
//displays 3 models
最佳答案
底层数据结构是数组。大多数 Backbone.Collection 方法都在 this.models
上运行,它是一个数组。 Backbone 的伟大之处在于,可以轻松打开它并查看引擎盖下的内容 - 特别是使用其 annotated source .
关于javascript - Backbone 中集合/有序集的数据结构是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254993/