peekRecord()不起作用,但是peekAll()起作用 [英] peekRecord() is not working but peekAll() is working

查看:127
本文介绍了peekRecord()不起作用,但是peekAll()起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的后端始终以所有可用数据作为响应,这花费了大量时间。因此,我会定期重新加载商店,并计划使用peekAll()和peekRecord()。

My backend always responds with all available data and it took a considerably amount of time. So I'm reloading store periodically and I plan to use peekAll() and peekRecord().

我的代码是:

model: function() {
  return Ember.RSVP.hash({
    'clusters': this.store.peekAll('cluster'),
    'single': this.store.peekRecord('cluster', 'cluster::My')
});

执行代码时,起初我可以看到这两个项目都不包含内容。几秒钟后,将数据加载到存储区,我可以按预期在模板上看到内容集群。但是单仍然完全没有内容({{model.single}}在模板中不返回任何内容)。但是当我有一个操作按钮时:

When code is executed, at first I can see that both of these items do not contain content. After few seconds data are loaded to store and I can see content 'clusters' on template as expected. But 'single' is still completely without content ({{model.single}} does not return nothing in template). But when I have a button with action:

alert(this.store.peekRecord('cluster', 'cluster::My'));

我可以看到已找到记录。记录也可以通过Ember Inspector获得。

I can see that the record was found. Records are also available via Ember Inspector. What am I doing wrong that only peekAll() works in model for me.

推荐答案

这两种方法的语义分别是:

The semantics of both methods are:


  • store.peekAll 返回一个实时数组,该数组随商店更新而更新。 / li>
  • store.peekRecord 返回当前缓存中的对应对象,或 null ,并且不会更新。

  • store.peekAll returns a live array that is updated as the store is updated.
  • store.peekRecord returns the corresponding object in the current cache, or null, and it does not update.

因此,您正在观察的行为是预期的行为。如果要使用 peek 方法,我的建议是在从存储中获取任何数据之前,确保初始请求已完成加载。

So the behaviour you're observing is the expected one. If you want to use the peek methods, my advise is to make sure that the initial request has finished loading before fetching any data from the store.

这篇关于peekRecord()不起作用,但是peekAll()起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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