7.4 Models -- Pushing Records into the Store
一、概述
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的更多相关文章
- 7.6 Models -- Finding Records
Ember Data的store为检索一个类型的records提供一个接口. 一.Retrieving a single record(检索单记录) 1. 通过type和ID使用store.findR ...
- 7.5 Models -- Persisting Records
一.概述 1. 在Ember Data上以每个实例为基础,records被持久化.在DS.Model的任何一个实例上调用save()并且它将产生一个网络请求. 2. 下面是一些例子: var post ...
- Ember.js学习教程 -- 目录
写在前面的话: 公司的新项目需要用到Ember.js,版本为v1.13.0.由于网上关于Ember的资料非常少,所以只有硬着头皮看官网的Guides,为了加深印象和方便以后查阅就用自己拙劣的英语水平把 ...
- 7.9 Models -- Connection to An HTTP Server
一.概述 1. 如果你的Ember应用程序需要从一个HTTP服务器加载JSON数据,在你的服务器返回的任何格式中,配置Ember Data的过程将会加载records. 2. store使用一个被称为 ...
- Ext Store Proxy Ajax
使用Store ajax的方式来获取数据 <div id="grid1"> </div> <script> Ext.onReady(functi ...
- 7.12 Models -- Frequently Asked Questions
一.Should I use a query or a filter to seach records?我应该使用一个查询或者过滤器来搜索记录吗? 这取决于你想要搜索多少reocrds并且它们是否被加 ...
- 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 ...
- .NET 云原生架构师训练营(权限系统 代码实现 Store.EntityFramework)--学习笔记
目录 开发任务 代码实现 开发任务 DotNetNB.Security.Core:定义 core,models,Istore:实现 default memory store DotNetNB.Secu ...
- ExtJS4笔记 Data
The data package is what loads and saves all of the data in your application and consists of 41 clas ...
随机推荐
- How To MD5SUM --- 如何检查MD5值?
windows : Hash_1.0.4.exe 可以检查md5 https://help.ubuntu.com/community/HowToMD5SUM Introduction When on ...
- Android studio 插件安装
安装插件步骤 一 CodeGlance 最大的用途:可用于快速定位代码.显示在右侧 二 Android Studio Prettify 可以将代码中的字符串写在string.xml文件中 选中字符串鼠 ...
- Hive学习之数据去重
insert overwrite table store select t.p_key,t.sort_word from ( select p_key, sort_word , row_number( ...
- NC 的高级应用
高级用法: (1)作攻击程序用,例子: 格式1:type.exe c:\exploit.txt|nc -nvv 192.168.x.x 80 格式2:nc -nvv 192.168.x.x 80 &l ...
- powerDesigner根据sql脚本来逆向生成pdm等模型
一.问题概述 网上一般的博文都是说要建立数据源的方式来逆向或者正向. 我这人比较懒得折腾,更喜欢通过sql脚本的方式来做. 二.步骤 File-->New Model--> 然后: 注意上 ...
- php应用
1. php判断是否为数字 is_numeric() 这个函数就是检测参数是否为数字,如果是就返回true,如果不是就返回false is_numeric( 'abcd123' ) or die('提 ...
- UVA 1335 Beijing Guards(二分答案)
入口: https://cn.vjudge.net/problem/UVA-1335 [题意] 有n个人为成一个圈,其中第i个人想要r[i]种不同的礼物,相邻的两个人可以聊天,炫耀自己的礼物.如果两个 ...
- 【CF839E】Mother of Dragons 折半状压
[CF839E]Mother of Dragons 题意:给你一张n个点,m条边的无向图.你有k点能量,你可以把能量分配到任意一些点上,每个点分到的能量可以是一个非负实数.定义总能量为:对于所有边&l ...
- python开发环境搭建(python3.3.2+wing IDE4.1)
1.下载python http://www.wingide.com/downloads下载最新版python 2.下载Wing IDE http://wingware.com/downloads/wi ...
- eclipse+gnuarm+使用报错
Description Resource Path Location TypeProgram "echo" not found in PATH stm32 Project Prop ...