From ember guides,
The below methods, will return the Promise, it will be resolved to Record or RecordArray.
store.findAll()
returns a DS.PromiseArray
that fulfills to a DS.RecordArray
.
store.findRecord
returns a promise that will be resolved with the record
.
store.query()
returns a DS.PromiseArray
in the same way as findAll.
The below two are synchronus method, it will retrieve what is available in the store and returns record itself. it will not request the server to fetch data.
store.peekAll
directly returns a DS.RecordArray
.
store.peekRecord
direclty returns record
It's important to note that DS.RecordArray
is not a JavaScript
array, it's an object that implements Ember.Enumerable
. This is
important because, for example, if you want to retrieve records by
index, the [] notation will not work--you'll have to use
objectAt(index)
instead.
From Ember.Enumerable, most of the time I happened to use the following,
forEach
to iterate
map
to transform to new Array
filterBy
findBy
for filtering based on single property check
toArray
converting to normal native array
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…