迭代一个ember模型查询 [英] Iterate over an ember model query

查看:145
本文介绍了迭代一个ember模型查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

($($)
$)$ b

我想知道如何使用结果变量。我明白我可以做

  results.get('firstObject')//返回第一个对象。 

我想知道我可以做的一切事情。



谢谢!

解决方案从

指南,



以下方法将返回Promise,它将被解析为Record或RecordArray。



store.findAll()返回一个符合的DS.PromiseArray DS.RecordArray

store.findRecord 返回一个将通过记录解决的承诺

store.query()返回一个 DS.PromiseArray 以与findAll相同的方式。



下面的两个是同步方法,它将检索商店中可用的内容并返回记录本身。它不会要求服务器提取数据。



store.peekAll 直接返回一个 DS.RecordArray

store.peekRecord direclty返回记录



< blockquote>

请注意, DS.RecordArray 不是JavaScript
数组,它是一个实现 Ember.Enumerable 。这是
重要,因为例如,如果要通过
索引检索记录,则[]符号将无法正常工作 - 您必须使用
objectAt(index)


Ember.Enumerable ,大多数时候我碰巧使用以下内容,

forEach 迭代

map 转换为新数组

filterBy findBy 用于基于单个属性检查的过滤

toArray 转换为普通原生数组


this.store.findAll('game').then(function(results){
   // RUN SOME OPERATION ON THEM
})

I would like to know how I can play with the results variable. I understand I can do

results.get('firstObject') // returns the first object.

I'd like to know everything else I can do with it. Is there any api documentation for the results collection?

Thanks!

解决方案

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

这篇关于迭代一个ember模型查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆