一、概述

1. store是作为一个所有records的缓存,这些records已经被你的应用程序加载。在你的app中如果你的路由或者一个controller请求一条record,如果它在缓存中这个store可以立即返回它。否则,这个store必须请求adapter去加载它,这通常意味着从服务器上进行网络访问去检索它。而不是等待应用程序去请求一条record,然而 ,你可以提前把records推送到store的缓存中。

2. 这是有用的,如果你能很好地意识到用户接下来需要什么records。当他们点击一个链接,而不是等待一个网络请求完成,Ember.js可以立刻渲染模板。感觉是一瞬间的。

3. 推送到records的另一个用例是如果你的应用程序有一个流连接到后端。如果一条record被创建或者修改,你想立即更新UI。

二、Pushing records

1. 调用store的push()方法来推送一条record到store。

2. 例如,假设当应用程序第一次启动时,我们想提前加载一些数据到store中。我们可以使用route:application来这样做。route:application是在路由层次中最顶级的路由,并且当app启动的时候它的model hook会被调用一次。

app/models/album.js

export default DS.Model.extend({
title: DS.attr(),
artist: DS.attr(),
songCount: DS.attr()
});

app/routes/application.js

export default Ember.Route.extend({
model() {
this.store.push('album', {
id: 1,
title: "Fewer Moving Parts",
artist: "David Bazan",
songCount: 10
}); this.store.push('album', {
id: 2,
title: "Calgary b/w I Can't Make You Love Me/Nick Of Time",
artist: "Bon Iver",
songCount: 2
});
}
});

7.4 Models -- Pushing Records into the Store的更多相关文章

  1. 7.6 Models -- Finding Records

    Ember Data的store为检索一个类型的records提供一个接口. 一.Retrieving a single record(检索单记录) 1. 通过type和ID使用store.findR ...

  2. 7.5 Models -- Persisting Records

    一.概述 1. 在Ember Data上以每个实例为基础,records被持久化.在DS.Model的任何一个实例上调用save()并且它将产生一个网络请求. 2. 下面是一些例子: var post ...

  3. Ember.js学习教程 -- 目录

    写在前面的话: 公司的新项目需要用到Ember.js,版本为v1.13.0.由于网上关于Ember的资料非常少,所以只有硬着头皮看官网的Guides,为了加深印象和方便以后查阅就用自己拙劣的英语水平把 ...

  4. 7.9 Models -- Connection to An HTTP Server

    一.概述 1. 如果你的Ember应用程序需要从一个HTTP服务器加载JSON数据,在你的服务器返回的任何格式中,配置Ember Data的过程将会加载records. 2. store使用一个被称为 ...

  5. Ext Store Proxy Ajax

    使用Store ajax的方式来获取数据 <div id="grid1"> </div> <script> Ext.onReady(functi ...

  6. 7.12 Models -- Frequently Asked Questions

    一.Should I use a query or a filter to seach records?我应该使用一个查询或者过滤器来搜索记录吗? 这取决于你想要搜索多少reocrds并且它们是否被加 ...

  7. Method and apparatus for providing total and partial store ordering for a memory in multi-processor system

    An improved memory model and implementation is disclosed. The memory model includes a Total Store Or ...

  8. .NET 云原生架构师训练营(权限系统 代码实现 Store.EntityFramework)--学习笔记

    目录 开发任务 代码实现 开发任务 DotNetNB.Security.Core:定义 core,models,Istore:实现 default memory store DotNetNB.Secu ...

  9. ExtJS4笔记 Data

    The data package is what loads and saves all of the data in your application and consists of 41 clas ...

随机推荐

  1. C# XtraGrid的行指示器(RowIndicator)行号以及图标设置

    以下是几种对Xtragrid的行指示器的几种操作方法,在实际场景当中,很多都需要用到,直接上效果图和源码 一.基本篇—设置表头行号 1.效果图 2.实现方法 需要对XtraGrid事件CustomDr ...

  2. Unity3D动作资源(AnimatinClip)优化

    能做到去掉Scale曲线,降低浮点精度 using System; using UnityEngine; using System.Collections; using System.Collecti ...

  3. C语言assert()函数用法总结

    assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h> void assert( i ...

  4. 一、laya学习笔记 --- layabox环境搭建 HelloWorld(坑:ts版本问题解决方案)

    好吧,使用layabox需要从官网下载些啥呢 一.下载layabox 官网 https://www.layabox.com/ 首页上有两个,一个Engine,一个IDE Engine我下载的TS版本, ...

  5. Function学习

    ---恢复内容开始--- Function的定义: 1.函数声明 function sum1(){ alert("sum1") } 2.函数表达式 var sum2 = funct ...

  6. iptables黑/白名单设置(使用ipset 工具)

    ipset介绍 ipset是iptables的扩展,它允许你创建 匹配整个地址集合的规则.而不像普通的iptables链只能单IP匹配, ip集合存储在带索引的数据结构中,这种结构即时集合比较大也可以 ...

  7. 9.20 session

    2018-9-20 13:14:40 Cookie session 参考 :http://www.cnblogs.com/liwenzhou/p/8343243.html 类视图  cbv 注册 ur ...

  8. poj3168 Barn Expansion【计算几何 平面扫描】

    Farmer John has N (1 <= N <= 25,000) rectangular barns on his farm, all with sides parallel to ...

  9. 同样的神经网络引擎,苹果A11芯片比华为麒麟970牛在哪?

    本文编辑:Cynthia iPhone X发布之后,999美元的售价并没有让人止步,相反,新iPhone的Face ID等功能让越来越多的人期待,库克在<早安美国>节目里也说了,iPhon ...

  10. DS作业·写了一个链表

    用struct手写了个list 有push_back,push_front,insert,erase reserve,size,setpos,rbegin 功能. 坑:一开始想用template< ...